atomic-fns 0.3.5 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/{core → dist}/collections/BTree.d.ts +6 -6
- package/{core → dist}/collections/BTree.js +17 -17
- package/{core → dist}/collections/Heap.d.ts +3 -3
- package/{core → dist}/collections/Heap.js +0 -0
- package/dist/collections/LRUCache.d.ts +80 -0
- package/dist/collections/LRUCache.js +126 -0
- package/{core → dist}/collections/SortedMap.d.ts +2 -2
- package/{core → dist}/collections/SortedMap.js +0 -0
- package/{core → dist}/collections/SortedSet.d.ts +3 -3
- package/{core → dist}/collections/SortedSet.js +1 -1
- package/{core → dist}/collections/SortedTree.d.ts +3 -3
- package/{core → dist}/collections/SortedTree.js +1 -1
- package/{core → dist}/collections/SplayTree.d.ts +5 -5
- package/{core → dist}/collections/SplayTree.js +0 -0
- package/{core → dist}/collections/abc.d.ts +0 -0
- package/{core → dist}/collections/abc.js +0 -0
- package/{core → dist}/collections/deque.d.ts +6 -6
- package/{core → dist}/collections/deque.js +0 -0
- package/{core → dist}/collections/frozenset.d.ts +0 -0
- package/{core → dist}/collections/frozenset.js +3 -6
- package/{core → dist}/collections/index.d.ts +4 -4
- package/{core → dist}/collections/index.js +0 -0
- package/{core → dist}/functools/index.d.ts +27 -13
- package/{core → dist}/functools/index.js +34 -12
- package/{core → dist}/globals/index.d.ts +7 -10
- package/{core → dist}/globals/index.js +7 -14
- package/dist/i18n/date/index.d.ts +204 -0
- package/dist/i18n/date/index.js +530 -0
- package/dist/i18n/date/utils.d.ts +65 -0
- package/dist/i18n/date/utils.js +312 -0
- package/dist/i18n/duration.d.ts +112 -0
- package/dist/i18n/duration.js +392 -0
- package/dist/i18n/format.d.ts +26 -0
- package/dist/i18n/format.js +495 -0
- package/{core → dist}/i18n/index.d.ts +1 -1
- package/{core → dist}/i18n/index.js +1 -1
- package/{core → dist}/index.d.ts +0 -0
- package/{core → dist}/index.js +0 -0
- package/{core → dist}/itertools/index.d.ts +27 -27
- package/{core → dist}/itertools/index.js +24 -24
- package/{core → dist}/math/index.d.ts +3 -3
- package/{core → dist}/math/index.js +0 -0
- package/{core → dist}/operators/index.d.ts +2 -2
- package/{core → dist}/operators/index.js +2 -2
- package/{core → dist}/random/index.d.ts +1 -1
- package/{core → dist}/random/index.js +3 -3
- package/package.json +28 -42
- package/.editorconfig +0 -12
- package/.esdoc.json +0 -27
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -35
- package/.firebaserc +0 -5
- package/.prettierrc +0 -19
- package/core/collections/BTree.ts +0 -1340
- package/core/collections/Heap.ts +0 -189
- package/core/collections/LRUCache.d.ts +0 -152
- package/core/collections/LRUCache.js +0 -409
- package/core/collections/LRUCache.ts +0 -486
- package/core/collections/SortedMap.ts +0 -146
- package/core/collections/SortedSet.ts +0 -110
- package/core/collections/SortedTree.ts +0 -160
- package/core/collections/SplayTree.ts +0 -354
- package/core/collections/abc.ts +0 -176
- package/core/collections/deque.ts +0 -338
- package/core/collections/frozenset.ts +0 -37
- package/core/collections/index.ts +0 -1024
- package/core/collections/test.html +0 -10
- package/core/collections/typedArrays.d.ts +0 -31
- package/core/collections/typedArrays.js +0 -143
- package/core/collections/typedArrays.ts +0 -163
- package/core/functools/index.ts +0 -260
- package/core/globals/index.ts +0 -481
- package/core/i18n/date/format.d.ts +0 -16
- package/core/i18n/date/format.js +0 -307
- package/core/i18n/date/format.ts +0 -343
- package/core/i18n/date/index.d.ts +0 -224
- package/core/i18n/date/index.js +0 -387
- package/core/i18n/date/index.ts +0 -471
- package/core/i18n/date/test.html +0 -67
- package/core/i18n/index.ts +0 -8
- package/core/index.ts +0 -8
- package/core/itertools/index.ts +0 -494
- package/core/math/index.ts +0 -152
- package/core/operators/index.ts +0 -310
- package/core/random/index.ts +0 -66
- package/firebase.json +0 -10
- package/jasmine.json +0 -14
- package/tests/BTree.spec.ts +0 -143
- package/tests/Cache.spec.ts +0 -161
- package/tests/Heap.spec.ts +0 -66
- package/tests/SortedMap.spec.ts +0 -144
- package/tests/SortedSet.spec.ts +0 -84
- package/tests/SortedTree.spec.ts +0 -164
- package/tests/SplayTree.spec.ts +0 -121
- package/tests/collections.spec.ts +0 -288
- package/tests/deque.spec.ts +0 -107
- package/tests/globals.spec.ts +0 -270
- package/tests/itertools.spec.ts +0 -266
- package/tests/math.spec.ts +0 -25
- package/tests/operators.spec.ts +0 -40
- package/tests/random.spec.ts +0 -46
- package/tsconfig.json +0 -126
- package/tsconfig.node.json +0 -18
- package/tsconfig.xo.json +0 -9
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { isInteger, ValueError } from '../../globals/index.js';
|
|
2
|
+
function bestBy(arr, by, compare) {
|
|
3
|
+
if (arr.length === 0) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
return arr.reduce((best, next) => {
|
|
7
|
+
const pair = [by(next), next];
|
|
8
|
+
if (!best) {
|
|
9
|
+
return pair;
|
|
10
|
+
}
|
|
11
|
+
else if (compare(best[0], pair[0]) === best[0]) {
|
|
12
|
+
return best;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return pair;
|
|
16
|
+
}
|
|
17
|
+
}, null)[1];
|
|
18
|
+
}
|
|
19
|
+
// NUMBERS AND STRINGS
|
|
20
|
+
function integerBetween(thing, bottom, top) {
|
|
21
|
+
return isInteger(thing) && thing >= bottom && thing <= top;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns x % n but takes the sign of n instead of x
|
|
25
|
+
* @param x
|
|
26
|
+
* @param n
|
|
27
|
+
* @returns {number}
|
|
28
|
+
*/
|
|
29
|
+
function floorMod(x, n) {
|
|
30
|
+
return x - n * Math.floor(x / n);
|
|
31
|
+
}
|
|
32
|
+
function padStart(input, n = 2) {
|
|
33
|
+
const isNeg = input < 0;
|
|
34
|
+
let padded;
|
|
35
|
+
if (isNeg) {
|
|
36
|
+
padded = '-' + ('' + -input).padStart(n, '0');
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
padded = ('' + input).padStart(n, '0');
|
|
40
|
+
}
|
|
41
|
+
return padded;
|
|
42
|
+
}
|
|
43
|
+
function parseInteger(str) {
|
|
44
|
+
if (str != null && str !== '')
|
|
45
|
+
return parseInt(str, 10);
|
|
46
|
+
}
|
|
47
|
+
function parseFloating(str) {
|
|
48
|
+
if (str != null && str !== '')
|
|
49
|
+
return parseFloat(str);
|
|
50
|
+
}
|
|
51
|
+
function parseMilliseconds(str) {
|
|
52
|
+
if (str != null && str !== '') {
|
|
53
|
+
const f = parseFloat('0.' + str) * 1000;
|
|
54
|
+
return Math.floor(f);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function minDate(...dates) {
|
|
58
|
+
let ans = dates[0];
|
|
59
|
+
if (Array.isArray(ans)) {
|
|
60
|
+
dates = ans;
|
|
61
|
+
ans = ans[0];
|
|
62
|
+
}
|
|
63
|
+
for (let i = 1; i < dates.length; i++) {
|
|
64
|
+
if (dates[i].valueOf() < ans.valueOf()) {
|
|
65
|
+
ans = dates[i];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return ans;
|
|
69
|
+
}
|
|
70
|
+
export function maxDate(...dates) {
|
|
71
|
+
let ans = dates[0];
|
|
72
|
+
if (Array.isArray(ans)) {
|
|
73
|
+
dates = ans;
|
|
74
|
+
ans = ans[0];
|
|
75
|
+
}
|
|
76
|
+
for (let i = 1; i < dates.length; i++) {
|
|
77
|
+
if (dates[i].valueOf() > ans.valueOf()) {
|
|
78
|
+
ans = dates[i];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return ans;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns `true` if the year is a leap year, otherwise `false`.
|
|
85
|
+
* @param year The date year
|
|
86
|
+
* @returns {boolean} `true` if is a leap year
|
|
87
|
+
*/
|
|
88
|
+
export function isLeapYear(year) {
|
|
89
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the number of days in the given year.
|
|
93
|
+
* @param year The date year
|
|
94
|
+
* @returns {number} Number of days in year
|
|
95
|
+
*/
|
|
96
|
+
export function daysInYear(year) {
|
|
97
|
+
return isLeapYear(year) ? 366 : 365;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the number of days in the given date's month and year.
|
|
101
|
+
* @param date The specified date
|
|
102
|
+
* @returns {number} Number of days in month
|
|
103
|
+
*/
|
|
104
|
+
export function daysInMonth(date) {
|
|
105
|
+
const d = new Date(date), year = d.getFullYear(), month = d.getMonth() + 1;
|
|
106
|
+
const modMonth = floorMod(month - 1, 12) + 1, modYear = year + (month - modMonth) / 12;
|
|
107
|
+
if (modMonth === 2) {
|
|
108
|
+
return isLeapYear(modYear) ? 29 : 28;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][modMonth - 1];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// covert a calendar object to a local timestamp (epoch, but with the offset baked in)
|
|
115
|
+
function objToLocalTS(obj) {
|
|
116
|
+
let d = Date.UTC(obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond);
|
|
117
|
+
// for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
|
|
118
|
+
if (obj.year < 100 && obj.year >= 0) {
|
|
119
|
+
let dt = new Date(d);
|
|
120
|
+
dt.setUTCFullYear(dt.getUTCFullYear() - 1900);
|
|
121
|
+
d = dt.getTime();
|
|
122
|
+
}
|
|
123
|
+
return +d;
|
|
124
|
+
}
|
|
125
|
+
function untruncateYear(year) {
|
|
126
|
+
if (year > 99) {
|
|
127
|
+
return year;
|
|
128
|
+
}
|
|
129
|
+
else
|
|
130
|
+
return year > 60 ? 1900 + year : 2000 + year;
|
|
131
|
+
}
|
|
132
|
+
// PARSING
|
|
133
|
+
function parseZoneInfo(ts, offsetFormat, locale, timeZone) {
|
|
134
|
+
const date = new Date(ts), intlOpts = {
|
|
135
|
+
hourCycle: 'h23',
|
|
136
|
+
year: 'numeric',
|
|
137
|
+
month: '2-digit',
|
|
138
|
+
day: '2-digit',
|
|
139
|
+
hour: '2-digit',
|
|
140
|
+
minute: '2-digit',
|
|
141
|
+
timeZone
|
|
142
|
+
};
|
|
143
|
+
const modified = { timeZoneName: offsetFormat, ...intlOpts };
|
|
144
|
+
const parsed = new Intl.DateTimeFormat(locale, modified)
|
|
145
|
+
.formatToParts(date)
|
|
146
|
+
.find((m) => m.type.toLowerCase() === 'timezonename');
|
|
147
|
+
return parsed ? parsed.value : null;
|
|
148
|
+
}
|
|
149
|
+
// signedOffset('-5', '30') -> -330
|
|
150
|
+
function signedOffset(offHourStr, offMinuteStr) {
|
|
151
|
+
let offHour = parseInt(offHourStr, 10);
|
|
152
|
+
// don't || this because we want to preserve -0
|
|
153
|
+
if (Number.isNaN(offHour)) {
|
|
154
|
+
offHour = 0;
|
|
155
|
+
}
|
|
156
|
+
const offMin = parseInt(offMinuteStr, 10) || 0, offMinSigned = offHour < 0 || Object.is(offHour, -0) ? -offMin : offMin;
|
|
157
|
+
return offHour * 60 + offMinSigned;
|
|
158
|
+
}
|
|
159
|
+
// COERCION
|
|
160
|
+
export function asNumber(value) {
|
|
161
|
+
const numericValue = Number(value);
|
|
162
|
+
if (typeof value === 'boolean' || value === '' || Number.isNaN(numericValue))
|
|
163
|
+
throw new ValueError(`Invalid unit value ${value}`);
|
|
164
|
+
return numericValue;
|
|
165
|
+
}
|
|
166
|
+
function formatOffset(offset, format) {
|
|
167
|
+
const hours = Math.trunc(Math.abs(offset / 60)), minutes = Math.trunc(Math.abs(offset % 60)), sign = offset >= 0 ? '+' : '-';
|
|
168
|
+
switch (format) {
|
|
169
|
+
case 'short':
|
|
170
|
+
return `${sign}${padStart(hours, 2)}:${padStart(minutes, 2)}`;
|
|
171
|
+
case 'narrow':
|
|
172
|
+
return `${sign}${hours}${minutes > 0 ? `:${minutes}` : ''}`;
|
|
173
|
+
case 'techie':
|
|
174
|
+
return `${sign}${padStart(hours, 2)}${padStart(minutes, 2)}`;
|
|
175
|
+
default:
|
|
176
|
+
throw new RangeError(`Value format ${format} is out of range for property format`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function timeObject(obj) {
|
|
180
|
+
const { hour, minute, second, millisecond } = obj;
|
|
181
|
+
return { hour, minute, second, millisecond };
|
|
182
|
+
}
|
|
183
|
+
const ianaRegex = /[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;
|
|
184
|
+
const isoDuration = /^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;
|
|
185
|
+
function extractISODuration(match) {
|
|
186
|
+
const [s, yearStr, monthStr, weekStr, dayStr, hourStr, minuteStr, secondStr, millisecondsStr] = match;
|
|
187
|
+
const hasNegativePrefix = s[0] === '-';
|
|
188
|
+
const negativeSeconds = secondStr && secondStr[0] === '-';
|
|
189
|
+
const maybeNegate = (num, force = false) => num !== undefined && (force || (num && hasNegativePrefix)) ? -num : num;
|
|
190
|
+
return [
|
|
191
|
+
{
|
|
192
|
+
years: maybeNegate(parseFloating(yearStr)),
|
|
193
|
+
months: maybeNegate(parseFloating(monthStr)),
|
|
194
|
+
weeks: maybeNegate(parseFloating(weekStr)),
|
|
195
|
+
days: maybeNegate(parseFloating(dayStr)),
|
|
196
|
+
hours: maybeNegate(parseFloating(hourStr)),
|
|
197
|
+
minutes: maybeNegate(parseFloating(minuteStr)),
|
|
198
|
+
seconds: maybeNegate(parseFloating(secondStr), secondStr === '-0'),
|
|
199
|
+
milliseconds: maybeNegate(parseMilliseconds(millisecondsStr), negativeSeconds)
|
|
200
|
+
}
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
function parse(s, ...patterns) {
|
|
204
|
+
if (s == null) {
|
|
205
|
+
return [null, null];
|
|
206
|
+
}
|
|
207
|
+
for (const [regex, extractor] of patterns) {
|
|
208
|
+
const m = regex.exec(s);
|
|
209
|
+
if (m) {
|
|
210
|
+
return extractor(m);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return [null, null];
|
|
214
|
+
}
|
|
215
|
+
export function parseISODuration(s) {
|
|
216
|
+
return parse(s, [isoDuration, extractISODuration]);
|
|
217
|
+
}
|
|
218
|
+
function createUTCDate(...args) {
|
|
219
|
+
let date, y = args[0];
|
|
220
|
+
// the Date.UTC function remaps years 0-99 to 1900-1999
|
|
221
|
+
if (y < 100 && y >= 0) {
|
|
222
|
+
args = Array.from(arguments);
|
|
223
|
+
// preserve leap years using a full 400 year cycle, then reset
|
|
224
|
+
args[0] = y + 400;
|
|
225
|
+
date = new Date(Date.UTC.apply(null, args));
|
|
226
|
+
if (isFinite(date.getUTCFullYear())) {
|
|
227
|
+
date.setUTCFullYear(y);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
date = new Date(Date.UTC.apply(null, arguments));
|
|
232
|
+
}
|
|
233
|
+
return date;
|
|
234
|
+
}
|
|
235
|
+
function firstWeekOffset(year, dow, doy) {
|
|
236
|
+
var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
|
|
237
|
+
fwd = 7 + dow - doy,
|
|
238
|
+
// first-week day local weekday -- which local weekday is fwd
|
|
239
|
+
fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
|
|
240
|
+
return -fwdlw + fwd - 1;
|
|
241
|
+
}
|
|
242
|
+
// https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
|
|
243
|
+
function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
|
|
244
|
+
var localWeekday = (7 + weekday - dow) % 7, weekOffset = firstWeekOffset(year, dow, doy), dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset, resYear, resDayOfYear;
|
|
245
|
+
if (dayOfYear <= 0) {
|
|
246
|
+
resYear = year - 1;
|
|
247
|
+
resDayOfYear = daysInYear(resYear) + dayOfYear;
|
|
248
|
+
}
|
|
249
|
+
else if (dayOfYear > daysInYear(year)) {
|
|
250
|
+
resYear = year + 1;
|
|
251
|
+
resDayOfYear = dayOfYear - daysInYear(year);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
resYear = year;
|
|
255
|
+
resDayOfYear = dayOfYear;
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
year: resYear,
|
|
259
|
+
dayOfYear: resDayOfYear
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Returns the number of weeks in the specified year.
|
|
264
|
+
* @param year
|
|
265
|
+
* @param firstDayOfWeek
|
|
266
|
+
* @param firstDayOfYear
|
|
267
|
+
*/
|
|
268
|
+
export function weeksInYear(year, firstDayOfWeek = 1, firstDayOfYear = 1) {
|
|
269
|
+
var weekOffset = firstWeekOffset(year, firstDayOfWeek, firstDayOfYear), weekOffsetNext = firstWeekOffset(year + 1, firstDayOfWeek, firstDayOfYear);
|
|
270
|
+
return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Returns the week of the year for the specified date
|
|
274
|
+
* @param year
|
|
275
|
+
* @param dayOfYear
|
|
276
|
+
* @param firstDayOfWeek
|
|
277
|
+
* @param firstDayOfYear
|
|
278
|
+
* @returns
|
|
279
|
+
*/
|
|
280
|
+
export function weekOfYear(date, firstDayOfWeek = 1, firstDayOfYear = 1) {
|
|
281
|
+
const year = new Date(date).getFullYear();
|
|
282
|
+
const doy = dayOfYear(date);
|
|
283
|
+
let weekOffset = firstWeekOffset(year, firstDayOfWeek, firstDayOfYear), week = Math.floor((doy - weekOffset - 1) / 7) + 1, resWeek, resYear;
|
|
284
|
+
if (week < 1) {
|
|
285
|
+
resYear = year - 1;
|
|
286
|
+
resWeek = week + weeksInYear(resYear, firstDayOfWeek, firstDayOfYear);
|
|
287
|
+
}
|
|
288
|
+
else if (week > weeksInYear(year, firstDayOfWeek, firstDayOfYear)) {
|
|
289
|
+
resWeek = week - weeksInYear(year, firstDayOfWeek, firstDayOfYear);
|
|
290
|
+
resYear = year + 1;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
resYear = year;
|
|
294
|
+
resWeek = week;
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
week: resWeek,
|
|
298
|
+
year: resYear
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
export function isoWeeksInYear(year) {
|
|
302
|
+
return weeksInYear(year, 1, 4);
|
|
303
|
+
}
|
|
304
|
+
export function dayOfYear(input) {
|
|
305
|
+
input = new Date(input);
|
|
306
|
+
input.setHours(0);
|
|
307
|
+
input.setMinutes(0);
|
|
308
|
+
input.setSeconds(0);
|
|
309
|
+
input.setMilliseconds(0);
|
|
310
|
+
let start = new Date(input.getFullYear(), 0, 1, 0, 0, 0, 0);
|
|
311
|
+
return Math.round((+input - start.getTime()) / 864e5) + 1;
|
|
312
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export declare type DurationUnit = 'year' | 'years' | 'quarter' | 'quarters' | 'month' | 'months' | 'week' | 'weeks' | 'day' | 'days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds';
|
|
2
|
+
export interface TDuration {
|
|
3
|
+
years?: number;
|
|
4
|
+
months?: number;
|
|
5
|
+
weeks?: number;
|
|
6
|
+
days?: number;
|
|
7
|
+
hours?: number;
|
|
8
|
+
minutes?: number;
|
|
9
|
+
seconds?: number;
|
|
10
|
+
milliseconds?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const UNITS_PLURAL: Record<DurationUnit, DurationUnit>;
|
|
13
|
+
export declare class Duration {
|
|
14
|
+
values: TDuration;
|
|
15
|
+
private matrix;
|
|
16
|
+
constructor(dur?: number | TDuration | Duration, exact?: boolean);
|
|
17
|
+
/** Get the years. */
|
|
18
|
+
get years(): number;
|
|
19
|
+
/** Get the months. */
|
|
20
|
+
get months(): number;
|
|
21
|
+
/** Get the weeks. */
|
|
22
|
+
get weeks(): number;
|
|
23
|
+
/** Get the days. */
|
|
24
|
+
get days(): number;
|
|
25
|
+
/** Get the hours. */
|
|
26
|
+
get hours(): number;
|
|
27
|
+
/** et the minutes. */
|
|
28
|
+
get minutes(): number;
|
|
29
|
+
/** Get the seconds. */
|
|
30
|
+
get seconds(): number;
|
|
31
|
+
/** Get the milliseconds. */
|
|
32
|
+
get milliseconds(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Get the value of unit.
|
|
35
|
+
* @param {string} unit - a unit such as 'minute' or 'day'
|
|
36
|
+
* @example Duration.fromObject({years: 2, days: 3}).get('years') // 2
|
|
37
|
+
* @example Duration.fromObject({years: 2, days: 3}).get('months') // 0
|
|
38
|
+
* @example Duration.fromObject({years: 2, days: 3}).get('days') // 3
|
|
39
|
+
* @return {number}
|
|
40
|
+
*/
|
|
41
|
+
get(unit: any): any;
|
|
42
|
+
add(duration: TDuration): Duration;
|
|
43
|
+
/**
|
|
44
|
+
* Make this Duration shorter by the specified amount. Return a newly-constructed Duration.
|
|
45
|
+
* @param {Duration|Object|number} duration - The amount to subtract.
|
|
46
|
+
* @return {Duration}
|
|
47
|
+
*/
|
|
48
|
+
subtract(duration: any): Duration;
|
|
49
|
+
/**
|
|
50
|
+
* Return the negative of this Duration.
|
|
51
|
+
* @example
|
|
52
|
+
```js
|
|
53
|
+
new Duration({ hours: 1, seconds: 30 }).negated().toObject()
|
|
54
|
+
// { hours: -1, seconds: -30 }
|
|
55
|
+
```
|
|
56
|
+
* @returns {Duration}
|
|
57
|
+
*/
|
|
58
|
+
negated(): Duration;
|
|
59
|
+
/**
|
|
60
|
+
* Return the absolute values of this Duration.
|
|
61
|
+
* @example
|
|
62
|
+
```js
|
|
63
|
+
new Duration({ hours: 1, seconds: -30 }).abs().toObject()
|
|
64
|
+
// { hours: 1, seconds: 30 }
|
|
65
|
+
```
|
|
66
|
+
* @returns {Duration}
|
|
67
|
+
*/
|
|
68
|
+
abs(): Duration;
|
|
69
|
+
private shiftToAll;
|
|
70
|
+
private shiftTo;
|
|
71
|
+
total(unit: DurationUnit): number;
|
|
72
|
+
exact(unit?: DurationUnit): number | this;
|
|
73
|
+
toObject(): {
|
|
74
|
+
years?: number;
|
|
75
|
+
months?: number;
|
|
76
|
+
weeks?: number;
|
|
77
|
+
days?: number;
|
|
78
|
+
hours?: number;
|
|
79
|
+
minutes?: number;
|
|
80
|
+
seconds?: number;
|
|
81
|
+
milliseconds?: number;
|
|
82
|
+
};
|
|
83
|
+
normalize(): Duration;
|
|
84
|
+
rescale(): Duration;
|
|
85
|
+
/**
|
|
86
|
+
* Returns an ISO 8601-compliant string representation of this Duration.
|
|
87
|
+
* @see https://en.wikipedia.org/wiki/ISO_8601#Durations
|
|
88
|
+
* @example Duration.fromObject({ years: 3, seconds: 45 }).toString() // 'P3YT45S'
|
|
89
|
+
* @example Duration.fromObject({ months: 4, seconds: 45 }).toString() // 'P4MT45S'
|
|
90
|
+
* @example Duration.fromObject({ months: 5 }).toString() // 'P5M'
|
|
91
|
+
* @example Duration.fromObject({ minutes: 5 }).toString() // 'PT5M'
|
|
92
|
+
* @example Duration.fromObject({ milliseconds: 6 }).toString() // 'PT0.006S'
|
|
93
|
+
* @return {string}
|
|
94
|
+
*/
|
|
95
|
+
toISOString(): string;
|
|
96
|
+
toString(): string;
|
|
97
|
+
/**
|
|
98
|
+
* Create a Duration from an ISO 8601 duration string.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
```js
|
|
102
|
+
Duration.fromISO('P3Y6M1W4DT12H30M5S').toObject()
|
|
103
|
+
// { years: 3, months: 6, weeks: 1, days: 4, hours: 12, minutes: 30, seconds: 5 }
|
|
104
|
+
Duration.fromISO('PT23H').toObject()
|
|
105
|
+
// { hours: 23 }
|
|
106
|
+
Duration.fromISO('P5Y3M').toObject()
|
|
107
|
+
// { years: 5, months: 3 }
|
|
108
|
+
```
|
|
109
|
+
* @return {Duration}
|
|
110
|
+
*/
|
|
111
|
+
static fromISO(text: string): Duration;
|
|
112
|
+
}
|