@thi.ng/date 2.1.2 → 2.1.5
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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/checks.d.ts +2 -2
- package/checks.js +2 -2
- package/datetime.d.ts +6 -6
- package/datetime.js +6 -6
- package/format.d.ts +1 -1
- package/format.js +2 -2
- package/i18n.d.ts +12 -13
- package/i18n.js +12 -13
- package/internal/precision.d.ts +2 -2
- package/internal/precision.js +2 -2
- package/iterators.d.ts +20 -20
- package/iterators.js +20 -20
- package/package.json +9 -9
- package/relative.d.ts +17 -18
- package/relative.js +17 -18
- package/round.d.ts +16 -16
- package/round.js +16 -16
- package/timecode.d.ts +3 -3
- package/timecode.js +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/checks.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import type { MaybeDate } from "./api.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Coerces `x` to a native JS `Date` instance.
|
|
4
4
|
*
|
|
5
|
-
* @param x
|
|
5
|
+
* @param x -
|
|
6
6
|
*/
|
|
7
7
|
export declare const ensureDate: (x: MaybeDate) => Date;
|
|
8
8
|
/**
|
|
9
9
|
* Coerces `x` to a timestamp.
|
|
10
10
|
*
|
|
11
|
-
* @param x
|
|
11
|
+
* @param x -
|
|
12
12
|
*/
|
|
13
13
|
export declare const ensureEpoch: (x: MaybeDate) => number;
|
|
14
14
|
export declare const isLeapYear: (year: number) => boolean;
|
package/checks.js
CHANGED
|
@@ -4,7 +4,7 @@ import { isString } from "@thi.ng/checks/is-string";
|
|
|
4
4
|
/**
|
|
5
5
|
* Coerces `x` to a native JS `Date` instance.
|
|
6
6
|
*
|
|
7
|
-
* @param x
|
|
7
|
+
* @param x -
|
|
8
8
|
*/
|
|
9
9
|
export const ensureDate = (x) => isString(x) || isNumber(x)
|
|
10
10
|
? new Date(x)
|
|
@@ -14,7 +14,7 @@ export const ensureDate = (x) => isString(x) || isNumber(x)
|
|
|
14
14
|
/**
|
|
15
15
|
* Coerces `x` to a timestamp.
|
|
16
16
|
*
|
|
17
|
-
* @param x
|
|
17
|
+
* @param x -
|
|
18
18
|
*/
|
|
19
19
|
export const ensureEpoch = (x) => (implementsFunction(x, "getTime") ? x : ensureDate(x)).getTime();
|
|
20
20
|
export const isLeapYear = (year) => !(year % 4) && (!!(year % 100) || !(year % 400));
|
package/datetime.d.ts
CHANGED
|
@@ -38,14 +38,14 @@ export declare class DateTime implements ICopy<DateTime>, ICompare<MaybeDate>, I
|
|
|
38
38
|
* Returns true if this instance is before the given date, i.e. if
|
|
39
39
|
* `this.compare(d) < 0`.
|
|
40
40
|
*
|
|
41
|
-
* @param d
|
|
41
|
+
* @param d -
|
|
42
42
|
*/
|
|
43
43
|
isBefore(d: MaybeDate): boolean;
|
|
44
44
|
/**
|
|
45
45
|
* Returns true if this instance is before the given date, i.e. if
|
|
46
46
|
* `this.compare(d) > 0`.
|
|
47
47
|
*
|
|
48
|
-
* @param d
|
|
48
|
+
* @param d -
|
|
49
49
|
*/
|
|
50
50
|
isAfter(d: MaybeDate): boolean;
|
|
51
51
|
equiv(o: any): boolean;
|
|
@@ -88,8 +88,8 @@ export declare class DateTime implements ICopy<DateTime>, ICompare<MaybeDate>, I
|
|
|
88
88
|
* Returns a new `DateTime` instance relative to this date, but with given
|
|
89
89
|
* period added/subtracted.
|
|
90
90
|
*
|
|
91
|
-
* @param x
|
|
92
|
-
* @param prec
|
|
91
|
+
* @param x -
|
|
92
|
+
* @param prec -
|
|
93
93
|
*/
|
|
94
94
|
add(x: number, prec: Period): DateTime;
|
|
95
95
|
toDate(): Date;
|
|
@@ -110,13 +110,13 @@ export declare class DateTime implements ICopy<DateTime>, ICompare<MaybeDate>, I
|
|
|
110
110
|
/**
|
|
111
111
|
* Coerces `x` to a {@link DateTime} instance.
|
|
112
112
|
*
|
|
113
|
-
* @param x
|
|
113
|
+
* @param x -
|
|
114
114
|
*/
|
|
115
115
|
export declare const ensureDateTime: (x: MaybeDate, prec?: Precision) => DateTime;
|
|
116
116
|
/**
|
|
117
117
|
* Returns true if `x` is a {@link MaybeDate}.
|
|
118
118
|
*
|
|
119
|
-
* @param x
|
|
119
|
+
* @param x -
|
|
120
120
|
*/
|
|
121
121
|
export declare const maybeIsDate: (x: any) => boolean;
|
|
122
122
|
//# sourceMappingURL=datetime.d.ts.map
|
package/datetime.js
CHANGED
|
@@ -79,7 +79,7 @@ export class DateTime {
|
|
|
79
79
|
* Returns true if this instance is before the given date, i.e. if
|
|
80
80
|
* `this.compare(d) < 0`.
|
|
81
81
|
*
|
|
82
|
-
* @param d
|
|
82
|
+
* @param d -
|
|
83
83
|
*/
|
|
84
84
|
isBefore(d) {
|
|
85
85
|
return this.compare(d) < 0;
|
|
@@ -88,7 +88,7 @@ export class DateTime {
|
|
|
88
88
|
* Returns true if this instance is before the given date, i.e. if
|
|
89
89
|
* `this.compare(d) > 0`.
|
|
90
90
|
*
|
|
91
|
-
* @param d
|
|
91
|
+
* @param d -
|
|
92
92
|
*/
|
|
93
93
|
isAfter(d) {
|
|
94
94
|
return this.compare(d) > 0;
|
|
@@ -252,8 +252,8 @@ export class DateTime {
|
|
|
252
252
|
* Returns a new `DateTime` instance relative to this date, but with given
|
|
253
253
|
* period added/subtracted.
|
|
254
254
|
*
|
|
255
|
-
* @param x
|
|
256
|
-
* @param prec
|
|
255
|
+
* @param x -
|
|
256
|
+
* @param prec -
|
|
257
257
|
*/
|
|
258
258
|
add(x, prec) {
|
|
259
259
|
if (prec === "w")
|
|
@@ -312,12 +312,12 @@ export class DateTime {
|
|
|
312
312
|
/**
|
|
313
313
|
* Coerces `x` to a {@link DateTime} instance.
|
|
314
314
|
*
|
|
315
|
-
* @param x
|
|
315
|
+
* @param x -
|
|
316
316
|
*/
|
|
317
317
|
export const ensureDateTime = (x, prec = "t") => x instanceof DateTime ? x : new DateTime(x, prec);
|
|
318
318
|
/**
|
|
319
319
|
* Returns true if `x` is a {@link MaybeDate}.
|
|
320
320
|
*
|
|
321
|
-
* @param x
|
|
321
|
+
* @param x -
|
|
322
322
|
*/
|
|
323
323
|
export const maybeIsDate = (x) => x instanceof DateTime || x instanceof Date || isNumber(x) || isString(x);
|
package/format.d.ts
CHANGED
package/format.js
CHANGED
|
@@ -121,7 +121,7 @@ export const FORMATTERS = {
|
|
|
121
121
|
* Returns literal `"Z"` iff timezone offset is zero (UTC), else the same as
|
|
122
122
|
* `Z` formatter.
|
|
123
123
|
*
|
|
124
|
-
* @param d
|
|
124
|
+
* @param d -
|
|
125
125
|
*/
|
|
126
126
|
ZZ: (d, utc = false) => (utc ? "Z" : FORMATTERS.Z(d, utc)),
|
|
127
127
|
/**
|
|
@@ -162,7 +162,7 @@ export const FORMATTERS = {
|
|
|
162
162
|
* // "yyyy"
|
|
163
163
|
* ```
|
|
164
164
|
*
|
|
165
|
-
* @param fmt
|
|
165
|
+
* @param fmt -
|
|
166
166
|
*/
|
|
167
167
|
export const defFormat = (fmt) => (x, utc = false) => {
|
|
168
168
|
let d = ensureDate(x);
|
package/i18n.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Locale, LocaleSpec, LocaleUnit, Precision } from "./api.js";
|
|
|
4
4
|
* Sets {@link LOCALE} for formatting and fills in missing default values.
|
|
5
5
|
* Unless called explicitly, the package uses {@link EN_SHORT} by default.
|
|
6
6
|
*
|
|
7
|
-
* @param locale
|
|
7
|
+
* @param locale -
|
|
8
8
|
*/
|
|
9
9
|
export declare const setLocale: (locale: LocaleSpec) => Locale;
|
|
10
10
|
/**
|
|
@@ -14,8 +14,8 @@ export declare const setLocale: (locale: LocaleSpec) => Locale;
|
|
|
14
14
|
* `fn` will be called within a try/catch block and the previous locale will be
|
|
15
15
|
* restored even if `fn` throws an error.
|
|
16
16
|
*
|
|
17
|
-
* @param locale
|
|
18
|
-
* @param fn
|
|
17
|
+
* @param locale -
|
|
18
|
+
* @param fn -
|
|
19
19
|
*/
|
|
20
20
|
export declare const withLocale: <T>(locale: LocaleSpec, fn: Fn0<T>) => T;
|
|
21
21
|
export declare let LOCALE: Locale;
|
|
@@ -57,10 +57,10 @@ export declare const monthNames: () => string[];
|
|
|
57
57
|
* // "2 Jahren"
|
|
58
58
|
* ```
|
|
59
59
|
*
|
|
60
|
-
* @param x
|
|
61
|
-
* @param unit
|
|
62
|
-
* @param isDativ
|
|
63
|
-
* @param unitsOnly
|
|
60
|
+
* @param x -
|
|
61
|
+
* @param unit -
|
|
62
|
+
* @param isDativ -
|
|
63
|
+
* @param unitsOnly -
|
|
64
64
|
*/
|
|
65
65
|
export declare const units: (x: number, unit: Precision | LocaleUnit, isDativ?: boolean, unitsOnly?: boolean) => string;
|
|
66
66
|
/**
|
|
@@ -73,18 +73,17 @@ export declare const units: (x: number, unit: Precision | LocaleUnit, isDativ?:
|
|
|
73
73
|
* // "weniger als 1 Jahr"
|
|
74
74
|
* ```
|
|
75
75
|
*
|
|
76
|
-
* @param x
|
|
77
|
-
* @param unit
|
|
78
|
-
* @param isDativ
|
|
76
|
+
* @param x -
|
|
77
|
+
* @param unit -
|
|
78
|
+
* @param isDativ -
|
|
79
79
|
*/
|
|
80
80
|
export declare const unitsLessThan: (x: number, unit: Precision | LocaleUnit, isDativ?: boolean) => string;
|
|
81
81
|
/**
|
|
82
82
|
* Wraps given (presumably localized) string in current {@link LOCALE}'s `past`
|
|
83
83
|
* or `future` phrases, depending on given `sign`.
|
|
84
84
|
*
|
|
85
|
-
* @param sign
|
|
86
|
-
* @param res
|
|
87
|
-
* @returns
|
|
85
|
+
* @param sign -
|
|
86
|
+
* @param res -
|
|
88
87
|
*/
|
|
89
88
|
export declare const tense: (sign: number, res: string) => string;
|
|
90
89
|
//# sourceMappingURL=i18n.d.ts.map
|
package/i18n.js
CHANGED
|
@@ -18,7 +18,7 @@ const prepLocale = (spec) => {
|
|
|
18
18
|
* Sets {@link LOCALE} for formatting and fills in missing default values.
|
|
19
19
|
* Unless called explicitly, the package uses {@link EN_SHORT} by default.
|
|
20
20
|
*
|
|
21
|
-
* @param locale
|
|
21
|
+
* @param locale -
|
|
22
22
|
*/
|
|
23
23
|
export const setLocale = (locale) => (LOCALE = prepLocale(locale));
|
|
24
24
|
/**
|
|
@@ -28,8 +28,8 @@ export const setLocale = (locale) => (LOCALE = prepLocale(locale));
|
|
|
28
28
|
* `fn` will be called within a try/catch block and the previous locale will be
|
|
29
29
|
* restored even if `fn` throws an error.
|
|
30
30
|
*
|
|
31
|
-
* @param locale
|
|
32
|
-
* @param fn
|
|
31
|
+
* @param locale -
|
|
32
|
+
* @param fn -
|
|
33
33
|
*/
|
|
34
34
|
export const withLocale = (locale, fn) => {
|
|
35
35
|
const old = LOCALE;
|
|
@@ -83,10 +83,10 @@ export const monthNames = () => LOCALE.months.slice();
|
|
|
83
83
|
* // "2 Jahren"
|
|
84
84
|
* ```
|
|
85
85
|
*
|
|
86
|
-
* @param x
|
|
87
|
-
* @param unit
|
|
88
|
-
* @param isDativ
|
|
89
|
-
* @param unitsOnly
|
|
86
|
+
* @param x -
|
|
87
|
+
* @param unit -
|
|
88
|
+
* @param isDativ -
|
|
89
|
+
* @param unitsOnly -
|
|
90
90
|
*/
|
|
91
91
|
export const units = (x, unit, isDativ = false, unitsOnly = false) => {
|
|
92
92
|
unit = isString(unit) ? LOCALE.units[unit] : unit;
|
|
@@ -109,17 +109,16 @@ export const units = (x, unit, isDativ = false, unitsOnly = false) => {
|
|
|
109
109
|
* // "weniger als 1 Jahr"
|
|
110
110
|
* ```
|
|
111
111
|
*
|
|
112
|
-
* @param x
|
|
113
|
-
* @param unit
|
|
114
|
-
* @param isDativ
|
|
112
|
+
* @param x -
|
|
113
|
+
* @param unit -
|
|
114
|
+
* @param isDativ -
|
|
115
115
|
*/
|
|
116
116
|
export const unitsLessThan = (x, unit, isDativ = false) => `${LOCALE.less.replace("%s", String(x))} ${units(Math.max(x, 1), unit, isDativ, true)}`;
|
|
117
117
|
/**
|
|
118
118
|
* Wraps given (presumably localized) string in current {@link LOCALE}'s `past`
|
|
119
119
|
* or `future` phrases, depending on given `sign`.
|
|
120
120
|
*
|
|
121
|
-
* @param sign
|
|
122
|
-
* @param res
|
|
123
|
-
* @returns
|
|
121
|
+
* @param sign -
|
|
122
|
+
* @param res -
|
|
124
123
|
*/
|
|
125
124
|
export const tense = (sign, res) => (sign < 0 ? LOCALE.past : LOCALE.future).replace("%s", res);
|
package/internal/precision.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Precision } from "../api.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Converts a {@link Precision} into a numeric ID.
|
|
4
4
|
*
|
|
5
|
-
* @param prec
|
|
5
|
+
* @param prec -
|
|
6
6
|
*
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
@@ -10,7 +10,7 @@ export declare const __precisionToID: (prec: Precision) => number;
|
|
|
10
10
|
/**
|
|
11
11
|
* Inverse op of {@link __precisionToID}.
|
|
12
12
|
*
|
|
13
|
-
* @param id
|
|
13
|
+
* @param id -
|
|
14
14
|
*
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
package/internal/precision.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Converts a {@link Precision} into a numeric ID.
|
|
3
3
|
*
|
|
4
|
-
* @param prec
|
|
4
|
+
* @param prec -
|
|
5
5
|
*
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
@@ -9,7 +9,7 @@ export const __precisionToID = (prec) => "yMdhmst".indexOf(prec);
|
|
|
9
9
|
/**
|
|
10
10
|
* Inverse op of {@link __precisionToID}.
|
|
11
11
|
*
|
|
12
|
-
* @param id
|
|
12
|
+
* @param id -
|
|
13
13
|
*
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
package/iterators.d.ts
CHANGED
|
@@ -5,16 +5,16 @@ import { DateTime } from "./datetime.js";
|
|
|
5
5
|
* Higher-order epoch iterator factory. Returns iterator with configured
|
|
6
6
|
* precision and `tick` fn.
|
|
7
7
|
*
|
|
8
|
-
* @param prec
|
|
9
|
-
* @param tick
|
|
8
|
+
* @param prec -
|
|
9
|
+
* @param tick -
|
|
10
10
|
*/
|
|
11
11
|
export declare const defIterator: (prec: Precision | Fn<number, DateTime>, tick: Fn<DateTime, void>) => EpochIteratorConstructor;
|
|
12
12
|
/**
|
|
13
13
|
* Yields iterator of UTC timestamps in given semi-open interval in yearly
|
|
14
14
|
* precision (each timestamp is at beginning of each year).
|
|
15
15
|
*
|
|
16
|
-
* @param from
|
|
17
|
-
* @param to
|
|
16
|
+
* @param from -
|
|
17
|
+
* @param to -
|
|
18
18
|
*/
|
|
19
19
|
export declare const years: EpochIteratorConstructor;
|
|
20
20
|
/**
|
|
@@ -22,16 +22,16 @@ export declare const years: EpochIteratorConstructor;
|
|
|
22
22
|
* precision (each timestamp is at beginning of a month), but spaced at 3 month
|
|
23
23
|
* intervals.
|
|
24
24
|
*
|
|
25
|
-
* @param from
|
|
26
|
-
* @param to
|
|
25
|
+
* @param from -
|
|
26
|
+
* @param to -
|
|
27
27
|
*/
|
|
28
28
|
export declare const quarters: EpochIteratorConstructor;
|
|
29
29
|
/**
|
|
30
30
|
* Yields iterator of UTC timestamps in given semi-open interval in monthly
|
|
31
31
|
* precision (each timestamp is at beginning of each month).
|
|
32
32
|
*
|
|
33
|
-
* @param from
|
|
34
|
-
* @param to
|
|
33
|
+
* @param from -
|
|
34
|
+
* @param to -
|
|
35
35
|
*/
|
|
36
36
|
export declare const months: EpochIteratorConstructor;
|
|
37
37
|
/**
|
|
@@ -39,48 +39,48 @@ export declare const months: EpochIteratorConstructor;
|
|
|
39
39
|
* precision (each timestamp is 7 days apart). As per ISO8601, weeks start on
|
|
40
40
|
* Mondays.
|
|
41
41
|
*
|
|
42
|
-
* @param from
|
|
43
|
-
* @param to
|
|
42
|
+
* @param from -
|
|
43
|
+
* @param to -
|
|
44
44
|
*/
|
|
45
45
|
export declare const weeks: EpochIteratorConstructor;
|
|
46
46
|
/**
|
|
47
47
|
* Yields iterator of UTC timestamps in given semi-open interval in daily
|
|
48
48
|
* precision (each timestamp is at midnight/beginning of each day).
|
|
49
49
|
*
|
|
50
|
-
* @param from
|
|
51
|
-
* @param to
|
|
50
|
+
* @param from -
|
|
51
|
+
* @param to -
|
|
52
52
|
*/
|
|
53
53
|
export declare const days: EpochIteratorConstructor;
|
|
54
54
|
/**
|
|
55
55
|
* Yields iterator of UTC timestamps in given semi-open interval in hourly
|
|
56
56
|
* precision.
|
|
57
57
|
*
|
|
58
|
-
* @param from
|
|
59
|
-
* @param to
|
|
58
|
+
* @param from -
|
|
59
|
+
* @param to -
|
|
60
60
|
*/
|
|
61
61
|
export declare const hours: EpochIteratorConstructor;
|
|
62
62
|
/**
|
|
63
63
|
* Yields iterator of UTC timestamps in given semi-open interval in minute
|
|
64
64
|
* precision.
|
|
65
65
|
*
|
|
66
|
-
* @param from
|
|
67
|
-
* @param to
|
|
66
|
+
* @param from -
|
|
67
|
+
* @param to -
|
|
68
68
|
*/
|
|
69
69
|
export declare const minutes: EpochIteratorConstructor;
|
|
70
70
|
/**
|
|
71
71
|
* Yields iterator of UTC timestamps in given semi-open interval in second
|
|
72
72
|
* precision.
|
|
73
73
|
*
|
|
74
|
-
* @param from
|
|
75
|
-
* @param to
|
|
74
|
+
* @param from -
|
|
75
|
+
* @param to -
|
|
76
76
|
*/
|
|
77
77
|
export declare const seconds: EpochIteratorConstructor;
|
|
78
78
|
/**
|
|
79
79
|
* Yields iterator of UTC timestamps in given semi-open interval in millisecond
|
|
80
80
|
* precision.
|
|
81
81
|
*
|
|
82
|
-
* @param from
|
|
83
|
-
* @param to
|
|
82
|
+
* @param from -
|
|
83
|
+
* @param to -
|
|
84
84
|
*/
|
|
85
85
|
export declare const milliseconds: EpochIteratorConstructor;
|
|
86
86
|
//# sourceMappingURL=iterators.d.ts.map
|
package/iterators.js
CHANGED
|
@@ -5,8 +5,8 @@ import { floorQuarter, floorWeek } from "./round.js";
|
|
|
5
5
|
* Higher-order epoch iterator factory. Returns iterator with configured
|
|
6
6
|
* precision and `tick` fn.
|
|
7
7
|
*
|
|
8
|
-
* @param prec
|
|
9
|
-
* @param tick
|
|
8
|
+
* @param prec -
|
|
9
|
+
* @param tick -
|
|
10
10
|
*/
|
|
11
11
|
export const defIterator = (prec, tick) => {
|
|
12
12
|
return function* (...xs) {
|
|
@@ -25,8 +25,8 @@ export const defIterator = (prec, tick) => {
|
|
|
25
25
|
* Yields iterator of UTC timestamps in given semi-open interval in yearly
|
|
26
26
|
* precision (each timestamp is at beginning of each year).
|
|
27
27
|
*
|
|
28
|
-
* @param from
|
|
29
|
-
* @param to
|
|
28
|
+
* @param from -
|
|
29
|
+
* @param to -
|
|
30
30
|
*/
|
|
31
31
|
export const years = defIterator("y", (d) => d.incYear());
|
|
32
32
|
/**
|
|
@@ -34,16 +34,16 @@ export const years = defIterator("y", (d) => d.incYear());
|
|
|
34
34
|
* precision (each timestamp is at beginning of a month), but spaced at 3 month
|
|
35
35
|
* intervals.
|
|
36
36
|
*
|
|
37
|
-
* @param from
|
|
38
|
-
* @param to
|
|
37
|
+
* @param from -
|
|
38
|
+
* @param to -
|
|
39
39
|
*/
|
|
40
40
|
export const quarters = defIterator((from) => new DateTime(floorQuarter(from)), (d) => d.incQuarter());
|
|
41
41
|
/**
|
|
42
42
|
* Yields iterator of UTC timestamps in given semi-open interval in monthly
|
|
43
43
|
* precision (each timestamp is at beginning of each month).
|
|
44
44
|
*
|
|
45
|
-
* @param from
|
|
46
|
-
* @param to
|
|
45
|
+
* @param from -
|
|
46
|
+
* @param to -
|
|
47
47
|
*/
|
|
48
48
|
export const months = defIterator("M", (d) => d.incMonth());
|
|
49
49
|
/**
|
|
@@ -51,47 +51,47 @@ export const months = defIterator("M", (d) => d.incMonth());
|
|
|
51
51
|
* precision (each timestamp is 7 days apart). As per ISO8601, weeks start on
|
|
52
52
|
* Mondays.
|
|
53
53
|
*
|
|
54
|
-
* @param from
|
|
55
|
-
* @param to
|
|
54
|
+
* @param from -
|
|
55
|
+
* @param to -
|
|
56
56
|
*/
|
|
57
57
|
export const weeks = defIterator((from) => new DateTime(floorWeek(from)), (d) => d.incWeek());
|
|
58
58
|
/**
|
|
59
59
|
* Yields iterator of UTC timestamps in given semi-open interval in daily
|
|
60
60
|
* precision (each timestamp is at midnight/beginning of each day).
|
|
61
61
|
*
|
|
62
|
-
* @param from
|
|
63
|
-
* @param to
|
|
62
|
+
* @param from -
|
|
63
|
+
* @param to -
|
|
64
64
|
*/
|
|
65
65
|
export const days = defIterator("d", (d) => d.incDay());
|
|
66
66
|
/**
|
|
67
67
|
* Yields iterator of UTC timestamps in given semi-open interval in hourly
|
|
68
68
|
* precision.
|
|
69
69
|
*
|
|
70
|
-
* @param from
|
|
71
|
-
* @param to
|
|
70
|
+
* @param from -
|
|
71
|
+
* @param to -
|
|
72
72
|
*/
|
|
73
73
|
export const hours = defIterator("h", (d) => d.incHour());
|
|
74
74
|
/**
|
|
75
75
|
* Yields iterator of UTC timestamps in given semi-open interval in minute
|
|
76
76
|
* precision.
|
|
77
77
|
*
|
|
78
|
-
* @param from
|
|
79
|
-
* @param to
|
|
78
|
+
* @param from -
|
|
79
|
+
* @param to -
|
|
80
80
|
*/
|
|
81
81
|
export const minutes = defIterator("m", (d) => d.incMinute());
|
|
82
82
|
/**
|
|
83
83
|
* Yields iterator of UTC timestamps in given semi-open interval in second
|
|
84
84
|
* precision.
|
|
85
85
|
*
|
|
86
|
-
* @param from
|
|
87
|
-
* @param to
|
|
86
|
+
* @param from -
|
|
87
|
+
* @param to -
|
|
88
88
|
*/
|
|
89
89
|
export const seconds = defIterator("s", (d) => d.incSecond());
|
|
90
90
|
/**
|
|
91
91
|
* Yields iterator of UTC timestamps in given semi-open interval in millisecond
|
|
92
92
|
* precision.
|
|
93
93
|
*
|
|
94
|
-
* @param from
|
|
95
|
-
* @param to
|
|
94
|
+
* @param from -
|
|
95
|
+
* @param to -
|
|
96
96
|
*/
|
|
97
97
|
export const milliseconds = defIterator("t", (d) => d.incMillisecond());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/date",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "Datetime types, relative dates, math, iterators, composable formatters, locales",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.3.
|
|
38
|
-
"@thi.ng/checks": "^3.1.
|
|
39
|
-
"@thi.ng/strings": "^3.
|
|
37
|
+
"@thi.ng/api": "^8.3.4",
|
|
38
|
+
"@thi.ng/checks": "^3.1.4",
|
|
39
|
+
"@thi.ng/strings": "^3.3.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@microsoft/api-extractor": "^7.
|
|
43
|
-
"@thi.ng/testament": "^0.2.
|
|
42
|
+
"@microsoft/api-extractor": "^7.19.4",
|
|
43
|
+
"@thi.ng/testament": "^0.2.4",
|
|
44
44
|
"rimraf": "^3.0.2",
|
|
45
45
|
"tools": "^0.0.1",
|
|
46
|
-
"typedoc": "^0.22.
|
|
47
|
-
"typescript": "^4.
|
|
46
|
+
"typedoc": "^0.22.13",
|
|
47
|
+
"typescript": "^4.6.2"
|
|
48
48
|
},
|
|
49
49
|
"keywords": [
|
|
50
50
|
"datastructure",
|
|
@@ -129,5 +129,5 @@
|
|
|
129
129
|
"thi.ng": {
|
|
130
130
|
"year": 2020
|
|
131
131
|
},
|
|
132
|
-
"gitHead": "
|
|
132
|
+
"gitHead": "0fc692a3225c068aacafdc4cb6140cf603c67ad8\n"
|
|
133
133
|
}
|
package/relative.d.ts
CHANGED
|
@@ -34,8 +34,8 @@ import { DateTime } from "./datetime.js";
|
|
|
34
34
|
* - `q` / `quarter` / `quarters`
|
|
35
35
|
* - `y` / `year` / `years`
|
|
36
36
|
*
|
|
37
|
-
* @param offset
|
|
38
|
-
* @param base
|
|
37
|
+
* @param offset -
|
|
38
|
+
* @param base -
|
|
39
39
|
*/
|
|
40
40
|
export declare const parseRelative: (offset: string, base?: MaybeDate | undefined) => DateTime | undefined;
|
|
41
41
|
/**
|
|
@@ -43,18 +43,17 @@ export declare const parseRelative: (offset: string, base?: MaybeDate | undefine
|
|
|
43
43
|
* optionally given `base` date (default: now). If `num < 0` the result date
|
|
44
44
|
* will be in the past (relative to `base`).
|
|
45
45
|
*
|
|
46
|
-
* @param num
|
|
47
|
-
* @param period
|
|
48
|
-
* @param base
|
|
49
|
-
* @returns
|
|
46
|
+
* @param num -
|
|
47
|
+
* @param period -
|
|
48
|
+
* @param base -
|
|
50
49
|
*/
|
|
51
50
|
export declare const relative: (num: number, period: Period, base?: MaybeDate) => DateTime;
|
|
52
51
|
/**
|
|
53
52
|
* Returns the signed difference in milliseconds between given two dates `a` and
|
|
54
53
|
* `b`.
|
|
55
54
|
*
|
|
56
|
-
* @param a
|
|
57
|
-
* @param b
|
|
55
|
+
* @param a -
|
|
56
|
+
* @param b -
|
|
58
57
|
*/
|
|
59
58
|
export declare const difference: (a: MaybeDate, b: MaybeDate) => number;
|
|
60
59
|
/**
|
|
@@ -63,8 +62,8 @@ export declare const difference: (a: MaybeDate, b: MaybeDate) => number;
|
|
|
63
62
|
* to indicate the relative order of `a` compared to `b`, i.e. same contract as
|
|
64
63
|
* {@link @thi.ng/api#ICompare}.
|
|
65
64
|
*
|
|
66
|
-
* @param a
|
|
67
|
-
* @param b
|
|
65
|
+
* @param a -
|
|
66
|
+
* @param b -
|
|
68
67
|
*/
|
|
69
68
|
export declare const decomposeDifference: (a: MaybeDate, b?: MaybeDate) => number[];
|
|
70
69
|
/**
|
|
@@ -93,10 +92,10 @@ export declare const decomposeDifference: (a: MaybeDate, b?: MaybeDate) => numbe
|
|
|
93
92
|
* // "in 18 minutes"
|
|
94
93
|
* ```
|
|
95
94
|
*
|
|
96
|
-
* @param date
|
|
97
|
-
* @param base
|
|
98
|
-
* @param prec
|
|
99
|
-
* @param eps
|
|
95
|
+
* @param date -
|
|
96
|
+
* @param base -
|
|
97
|
+
* @param prec -
|
|
98
|
+
* @param eps -
|
|
100
99
|
*/
|
|
101
100
|
export declare const formatRelative: (date: MaybeDate, base?: MaybeDate, prec?: number, eps?: number) => string;
|
|
102
101
|
/**
|
|
@@ -124,10 +123,10 @@ export declare const formatRelative: (date: MaybeDate, base?: MaybeDate, prec?:
|
|
|
124
123
|
* // "in less than a day"
|
|
125
124
|
* ```
|
|
126
125
|
*
|
|
127
|
-
* @param date
|
|
128
|
-
* @param base
|
|
129
|
-
* @param prec
|
|
130
|
-
* @param eps
|
|
126
|
+
* @param date -
|
|
127
|
+
* @param base -
|
|
128
|
+
* @param prec -
|
|
129
|
+
* @param eps -
|
|
131
130
|
*/
|
|
132
131
|
export declare const formatRelativeParts: (date: MaybeDate, base?: MaybeDate, prec?: Precision, eps?: number) => string;
|
|
133
132
|
//# sourceMappingURL=relative.d.ts.map
|
package/relative.js
CHANGED
|
@@ -38,8 +38,8 @@ import { __idToPrecision, __precisionToID } from "./internal/precision.js";
|
|
|
38
38
|
* - `q` / `quarter` / `quarters`
|
|
39
39
|
* - `y` / `year` / `years`
|
|
40
40
|
*
|
|
41
|
-
* @param offset
|
|
42
|
-
* @param base
|
|
41
|
+
* @param offset -
|
|
42
|
+
* @param base -
|
|
43
43
|
*/
|
|
44
44
|
export const parseRelative = (offset, base) => {
|
|
45
45
|
offset = offset.toLowerCase();
|
|
@@ -100,18 +100,17 @@ const parsePeriod = (x) => {
|
|
|
100
100
|
* optionally given `base` date (default: now). If `num < 0` the result date
|
|
101
101
|
* will be in the past (relative to `base`).
|
|
102
102
|
*
|
|
103
|
-
* @param num
|
|
104
|
-
* @param period
|
|
105
|
-
* @param base
|
|
106
|
-
* @returns
|
|
103
|
+
* @param num -
|
|
104
|
+
* @param period -
|
|
105
|
+
* @param base -
|
|
107
106
|
*/
|
|
108
107
|
export const relative = (num, period, base = dateTime()) => dateTime(base).add(num, period);
|
|
109
108
|
/**
|
|
110
109
|
* Returns the signed difference in milliseconds between given two dates `a` and
|
|
111
110
|
* `b`.
|
|
112
111
|
*
|
|
113
|
-
* @param a
|
|
114
|
-
* @param b
|
|
112
|
+
* @param a -
|
|
113
|
+
* @param b -
|
|
115
114
|
*/
|
|
116
115
|
export const difference = (a, b) => ensureEpoch(a) - ensureEpoch(b);
|
|
117
116
|
/**
|
|
@@ -120,8 +119,8 @@ export const difference = (a, b) => ensureEpoch(a) - ensureEpoch(b);
|
|
|
120
119
|
* to indicate the relative order of `a` compared to `b`, i.e. same contract as
|
|
121
120
|
* {@link @thi.ng/api#ICompare}.
|
|
122
121
|
*
|
|
123
|
-
* @param a
|
|
124
|
-
* @param b
|
|
122
|
+
* @param a -
|
|
123
|
+
* @param b -
|
|
125
124
|
*/
|
|
126
125
|
export const decomposeDifference = (a, b = new Date()) => {
|
|
127
126
|
const dur = ensureEpoch(a) - ensureEpoch(b);
|
|
@@ -191,10 +190,10 @@ export const decomposeDifference = (a, b = new Date()) => {
|
|
|
191
190
|
* // "in 18 minutes"
|
|
192
191
|
* ```
|
|
193
192
|
*
|
|
194
|
-
* @param date
|
|
195
|
-
* @param base
|
|
196
|
-
* @param prec
|
|
197
|
-
* @param eps
|
|
193
|
+
* @param date -
|
|
194
|
+
* @param base -
|
|
195
|
+
* @param prec -
|
|
196
|
+
* @param eps -
|
|
198
197
|
*/
|
|
199
198
|
export const formatRelative = (date, base = new Date(), prec = 0, eps = 100) => {
|
|
200
199
|
const delta = difference(date, base);
|
|
@@ -258,10 +257,10 @@ export const formatRelative = (date, base = new Date(), prec = 0, eps = 100) =>
|
|
|
258
257
|
* // "in less than a day"
|
|
259
258
|
* ```
|
|
260
259
|
*
|
|
261
|
-
* @param date
|
|
262
|
-
* @param base
|
|
263
|
-
* @param prec
|
|
264
|
-
* @param eps
|
|
260
|
+
* @param date -
|
|
261
|
+
* @param base -
|
|
262
|
+
* @param prec -
|
|
263
|
+
* @param eps -
|
|
265
264
|
*/
|
|
266
265
|
export const formatRelativeParts = (date, base = Date.now(), prec = "s", eps = 1000) => {
|
|
267
266
|
date = ensureEpoch(date);
|
package/round.d.ts
CHANGED
|
@@ -2,99 +2,99 @@ import { RoundingFn } from "./api.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Rounds down `epoch` to minute precision.
|
|
4
4
|
*
|
|
5
|
-
* @param epoch
|
|
5
|
+
* @param epoch -
|
|
6
6
|
*/
|
|
7
7
|
export declare const floorSecond: RoundingFn;
|
|
8
8
|
/**
|
|
9
9
|
* Rounds down `epoch` to minute precision.
|
|
10
10
|
*
|
|
11
|
-
* @param epoch
|
|
11
|
+
* @param epoch -
|
|
12
12
|
*/
|
|
13
13
|
export declare const floorMinute: RoundingFn;
|
|
14
14
|
/**
|
|
15
15
|
* Rounds down `epoch` to hour precision.
|
|
16
16
|
*
|
|
17
|
-
* @param epoch
|
|
17
|
+
* @param epoch -
|
|
18
18
|
*/
|
|
19
19
|
export declare const floorHour: RoundingFn;
|
|
20
20
|
/**
|
|
21
21
|
* Rounds down `epoch` to day precision
|
|
22
22
|
*
|
|
23
|
-
* @param epoch
|
|
23
|
+
* @param epoch -
|
|
24
24
|
*/
|
|
25
25
|
export declare const floorDay: RoundingFn;
|
|
26
26
|
/**
|
|
27
27
|
* Rounds down `epoch` to week precision. Assumes ISO8601 week logic, i.e. weeks
|
|
28
28
|
* start on Monday.
|
|
29
29
|
*
|
|
30
|
-
* @param epoch
|
|
30
|
+
* @param epoch -
|
|
31
31
|
*/
|
|
32
32
|
export declare const floorWeek: RoundingFn;
|
|
33
33
|
/**
|
|
34
34
|
* Rounds down `epoch` to month precision.
|
|
35
35
|
*
|
|
36
|
-
* @param epoch
|
|
36
|
+
* @param epoch -
|
|
37
37
|
*/
|
|
38
38
|
export declare const floorMonth: RoundingFn;
|
|
39
39
|
/**
|
|
40
40
|
* Rounds down `epoch` to month precision, but at beginning of a quarter.
|
|
41
41
|
*
|
|
42
|
-
* @param epoch
|
|
42
|
+
* @param epoch -
|
|
43
43
|
*/
|
|
44
44
|
export declare const floorQuarter: RoundingFn;
|
|
45
45
|
/**
|
|
46
46
|
* Rounds down `epoch` to year precision.
|
|
47
47
|
*
|
|
48
|
-
* @param epoch
|
|
48
|
+
* @param epoch -
|
|
49
49
|
*/
|
|
50
50
|
export declare const floorYear: RoundingFn;
|
|
51
51
|
/**
|
|
52
52
|
* Rounds up `epoch` to minute precision.
|
|
53
53
|
*
|
|
54
|
-
* @param epoch
|
|
54
|
+
* @param epoch -
|
|
55
55
|
*/
|
|
56
56
|
export declare const ceilSecond: RoundingFn;
|
|
57
57
|
/**
|
|
58
58
|
* Rounds up `epoch` to minute precision.
|
|
59
59
|
*
|
|
60
|
-
* @param epoch
|
|
60
|
+
* @param epoch -
|
|
61
61
|
*/
|
|
62
62
|
export declare const ceilMinute: RoundingFn;
|
|
63
63
|
/**
|
|
64
64
|
* Rounds up `epoch` to hour precision.
|
|
65
65
|
*
|
|
66
|
-
* @param epoch
|
|
66
|
+
* @param epoch -
|
|
67
67
|
*/
|
|
68
68
|
export declare const ceilHour: RoundingFn;
|
|
69
69
|
/**
|
|
70
70
|
* Rounds up `epoch` to day precision
|
|
71
71
|
*
|
|
72
|
-
* @param epoch
|
|
72
|
+
* @param epoch -
|
|
73
73
|
*/
|
|
74
74
|
export declare const ceilDay: RoundingFn;
|
|
75
75
|
/**
|
|
76
76
|
* Rounds up `epoch` to week precision. Assumes ISO8601 week logic, i.e. weeks
|
|
77
77
|
* start on Monday.
|
|
78
78
|
*
|
|
79
|
-
* @param epoch
|
|
79
|
+
* @param epoch -
|
|
80
80
|
*/
|
|
81
81
|
export declare const ceilWeek: RoundingFn;
|
|
82
82
|
/**
|
|
83
83
|
* Rounds up `epoch` to month precision
|
|
84
84
|
*
|
|
85
|
-
* @param epoch
|
|
85
|
+
* @param epoch -
|
|
86
86
|
*/
|
|
87
87
|
export declare const ceilMonth: RoundingFn;
|
|
88
88
|
/**
|
|
89
89
|
* Rounds up `epoch` to month precision (beginning of next quarter)
|
|
90
90
|
*
|
|
91
|
-
* @param epoch
|
|
91
|
+
* @param epoch -
|
|
92
92
|
*/
|
|
93
93
|
export declare const ceilQuarter: RoundingFn;
|
|
94
94
|
/**
|
|
95
95
|
* Rounds up `epoch` to year precision
|
|
96
96
|
*
|
|
97
|
-
* @param epoch
|
|
97
|
+
* @param epoch -
|
|
98
98
|
*/
|
|
99
99
|
export declare const ceilYear: RoundingFn;
|
|
100
100
|
//# sourceMappingURL=round.d.ts.map
|
package/round.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ensureDate } from "./checks.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Rounds down `epoch` to minute precision.
|
|
5
5
|
*
|
|
6
|
-
* @param epoch
|
|
6
|
+
* @param epoch -
|
|
7
7
|
*/
|
|
8
8
|
export const floorSecond = (epoch) => {
|
|
9
9
|
const d = ensureDate(epoch);
|
|
@@ -12,7 +12,7 @@ export const floorSecond = (epoch) => {
|
|
|
12
12
|
/**
|
|
13
13
|
* Rounds down `epoch` to minute precision.
|
|
14
14
|
*
|
|
15
|
-
* @param epoch
|
|
15
|
+
* @param epoch -
|
|
16
16
|
*/
|
|
17
17
|
export const floorMinute = (epoch) => {
|
|
18
18
|
const d = ensureDate(epoch);
|
|
@@ -21,7 +21,7 @@ export const floorMinute = (epoch) => {
|
|
|
21
21
|
/**
|
|
22
22
|
* Rounds down `epoch` to hour precision.
|
|
23
23
|
*
|
|
24
|
-
* @param epoch
|
|
24
|
+
* @param epoch -
|
|
25
25
|
*/
|
|
26
26
|
export const floorHour = (epoch) => {
|
|
27
27
|
const d = ensureDate(epoch);
|
|
@@ -30,7 +30,7 @@ export const floorHour = (epoch) => {
|
|
|
30
30
|
/**
|
|
31
31
|
* Rounds down `epoch` to day precision
|
|
32
32
|
*
|
|
33
|
-
* @param epoch
|
|
33
|
+
* @param epoch -
|
|
34
34
|
*/
|
|
35
35
|
export const floorDay = (epoch) => {
|
|
36
36
|
const d = ensureDate(epoch);
|
|
@@ -40,7 +40,7 @@ export const floorDay = (epoch) => {
|
|
|
40
40
|
* Rounds down `epoch` to week precision. Assumes ISO8601 week logic, i.e. weeks
|
|
41
41
|
* start on Monday.
|
|
42
42
|
*
|
|
43
|
-
* @param epoch
|
|
43
|
+
* @param epoch -
|
|
44
44
|
*/
|
|
45
45
|
export const floorWeek = (epoch) => {
|
|
46
46
|
const d = ensureDate(epoch);
|
|
@@ -51,7 +51,7 @@ export const floorWeek = (epoch) => {
|
|
|
51
51
|
/**
|
|
52
52
|
* Rounds down `epoch` to month precision.
|
|
53
53
|
*
|
|
54
|
-
* @param epoch
|
|
54
|
+
* @param epoch -
|
|
55
55
|
*/
|
|
56
56
|
export const floorMonth = (epoch) => {
|
|
57
57
|
const d = ensureDate(epoch);
|
|
@@ -60,7 +60,7 @@ export const floorMonth = (epoch) => {
|
|
|
60
60
|
/**
|
|
61
61
|
* Rounds down `epoch` to month precision, but at beginning of a quarter.
|
|
62
62
|
*
|
|
63
|
-
* @param epoch
|
|
63
|
+
* @param epoch -
|
|
64
64
|
*/
|
|
65
65
|
export const floorQuarter = (epoch) => {
|
|
66
66
|
const d = ensureDate(epoch);
|
|
@@ -69,44 +69,44 @@ export const floorQuarter = (epoch) => {
|
|
|
69
69
|
/**
|
|
70
70
|
* Rounds down `epoch` to year precision.
|
|
71
71
|
*
|
|
72
|
-
* @param epoch
|
|
72
|
+
* @param epoch -
|
|
73
73
|
*/
|
|
74
74
|
export const floorYear = (epoch) => Date.UTC(ensureDate(epoch).getUTCFullYear(), 0);
|
|
75
75
|
/**
|
|
76
76
|
* Rounds up `epoch` to minute precision.
|
|
77
77
|
*
|
|
78
|
-
* @param epoch
|
|
78
|
+
* @param epoch -
|
|
79
79
|
*/
|
|
80
80
|
export const ceilSecond = (epoch) => floorSecond(ensureDate(epoch).getTime() + SECOND);
|
|
81
81
|
/**
|
|
82
82
|
* Rounds up `epoch` to minute precision.
|
|
83
83
|
*
|
|
84
|
-
* @param epoch
|
|
84
|
+
* @param epoch -
|
|
85
85
|
*/
|
|
86
86
|
export const ceilMinute = (epoch) => floorMinute(ensureDate(epoch).getTime() + MINUTE);
|
|
87
87
|
/**
|
|
88
88
|
* Rounds up `epoch` to hour precision.
|
|
89
89
|
*
|
|
90
|
-
* @param epoch
|
|
90
|
+
* @param epoch -
|
|
91
91
|
*/
|
|
92
92
|
export const ceilHour = (epoch) => floorHour(ensureDate(epoch).getTime() + HOUR);
|
|
93
93
|
/**
|
|
94
94
|
* Rounds up `epoch` to day precision
|
|
95
95
|
*
|
|
96
|
-
* @param epoch
|
|
96
|
+
* @param epoch -
|
|
97
97
|
*/
|
|
98
98
|
export const ceilDay = (epoch) => floorDay(ensureDate(epoch).getTime() + DAY);
|
|
99
99
|
/**
|
|
100
100
|
* Rounds up `epoch` to week precision. Assumes ISO8601 week logic, i.e. weeks
|
|
101
101
|
* start on Monday.
|
|
102
102
|
*
|
|
103
|
-
* @param epoch
|
|
103
|
+
* @param epoch -
|
|
104
104
|
*/
|
|
105
105
|
export const ceilWeek = (epoch) => floorWeek(ensureDate(epoch).getTime() + WEEK);
|
|
106
106
|
/**
|
|
107
107
|
* Rounds up `epoch` to month precision
|
|
108
108
|
*
|
|
109
|
-
* @param epoch
|
|
109
|
+
* @param epoch -
|
|
110
110
|
*/
|
|
111
111
|
export const ceilMonth = (epoch) => {
|
|
112
112
|
const d = ensureDate(epoch);
|
|
@@ -118,7 +118,7 @@ export const ceilMonth = (epoch) => {
|
|
|
118
118
|
/**
|
|
119
119
|
* Rounds up `epoch` to month precision (beginning of next quarter)
|
|
120
120
|
*
|
|
121
|
-
* @param epoch
|
|
121
|
+
* @param epoch -
|
|
122
122
|
*/
|
|
123
123
|
export const ceilQuarter = (epoch) => {
|
|
124
124
|
const d = ensureDate(epoch);
|
|
@@ -130,6 +130,6 @@ export const ceilQuarter = (epoch) => {
|
|
|
130
130
|
/**
|
|
131
131
|
* Rounds up `epoch` to year precision
|
|
132
132
|
*
|
|
133
|
-
* @param epoch
|
|
133
|
+
* @param epoch -
|
|
134
134
|
*/
|
|
135
135
|
export const ceilYear = (epoch) => Date.UTC(ensureDate(epoch).getUTCFullYear() + 1, 0);
|
package/timecode.d.ts
CHANGED
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
* // "01d 01h 02' 03" 29"
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
25
|
-
* @param fps
|
|
26
|
-
* @param sep
|
|
25
|
+
* @param fps -
|
|
26
|
+
* @param sep -
|
|
27
27
|
*/
|
|
28
28
|
export declare const defTimecode: (fps: number, sep?: ArrayLike<string>) => (t: number) => string;
|
|
29
29
|
/**
|
|
30
30
|
* Decomposes given duration (in milliseconds) into a tuple of: `[year, month,
|
|
31
31
|
* day, hour, minute, second, millis]`.
|
|
32
32
|
*
|
|
33
|
-
* @param dur
|
|
33
|
+
* @param dur -
|
|
34
34
|
*/
|
|
35
35
|
export declare const decomposeDuration: (dur: number) => number[];
|
|
36
36
|
//# sourceMappingURL=timecode.d.ts.map
|
package/timecode.js
CHANGED
|
@@ -24,8 +24,8 @@ import { DAY, HOUR, MINUTE, MONTH, SECOND, YEAR } from "./api.js";
|
|
|
24
24
|
* // "01d 01h 02' 03" 29"
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
|
-
* @param fps
|
|
28
|
-
* @param sep
|
|
27
|
+
* @param fps -
|
|
28
|
+
* @param sep -
|
|
29
29
|
*/
|
|
30
30
|
export const defTimecode = (fps, sep = "::::") => {
|
|
31
31
|
const frame = 1000 / fps;
|
|
@@ -48,7 +48,7 @@ export const defTimecode = (fps, sep = "::::") => {
|
|
|
48
48
|
* Decomposes given duration (in milliseconds) into a tuple of: `[year, month,
|
|
49
49
|
* day, hour, minute, second, millis]`.
|
|
50
50
|
*
|
|
51
|
-
* @param dur
|
|
51
|
+
* @param dur -
|
|
52
52
|
*/
|
|
53
53
|
export const decomposeDuration = (dur) => {
|
|
54
54
|
const year = (dur / YEAR) | 0;
|