@fr0st/datetime 8.0.0 → 8.0.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/dist/frost-datetime.js +270 -264
- package/dist/frost-datetime.js.map +1 -1
- package/dist/frost-datetime.min.js +1 -1
- package/dist/frost-datetime.min.js.map +1 -1
- package/package.json +1 -1
- package/src/date-time.js +214 -208
- package/src/factory.js +4 -4
- package/src/formatter/format.js +13 -13
- package/src/formatter/locale.js +3 -3
- package/src/formatter/parse.js +10 -10
- package/src/formatter/utility.js +5 -5
- package/src/formatter/values.js +10 -10
- package/src/helpers.js +11 -11
package/src/factory.js
CHANGED
|
@@ -16,7 +16,7 @@ export function clearDataCache() {
|
|
|
16
16
|
* @template T
|
|
17
17
|
* @param {string} key The key for the values.
|
|
18
18
|
* @param {() => T} callback The callback to generate the values.
|
|
19
|
-
* @
|
|
19
|
+
* @returns {T} The cached value.
|
|
20
20
|
*/
|
|
21
21
|
export function getData(key, callback) {
|
|
22
22
|
if (!data.has(key)) {
|
|
@@ -29,7 +29,7 @@ export function getData(key, callback) {
|
|
|
29
29
|
/**
|
|
30
30
|
* Creates a date formatter for a time zone.
|
|
31
31
|
* @param {string} timeZone The time zone.
|
|
32
|
-
* @
|
|
32
|
+
* @returns {Intl.DateTimeFormat} The formatter instance.
|
|
33
33
|
*/
|
|
34
34
|
export function getDateFormatter(timeZone) {
|
|
35
35
|
return getData(
|
|
@@ -52,7 +52,7 @@ export function getDateFormatter(timeZone) {
|
|
|
52
52
|
/**
|
|
53
53
|
* Creates a relative-time formatter for a locale.
|
|
54
54
|
* @param {string} locale The locale.
|
|
55
|
-
* @
|
|
55
|
+
* @returns {Intl.RelativeTimeFormat|null} The formatter instance, or null when unsupported.
|
|
56
56
|
*/
|
|
57
57
|
export function getRelativeFormatter(locale) {
|
|
58
58
|
if (!('RelativeTimeFormat' in Intl)) {
|
|
@@ -72,7 +72,7 @@ export function getRelativeFormatter(locale) {
|
|
|
72
72
|
* Creates a formatter for a locale.
|
|
73
73
|
* @param {string} locale The locale.
|
|
74
74
|
* @param {Intl.DateTimeFormatOptions} options The options for the formatter.
|
|
75
|
-
* @
|
|
75
|
+
* @returns {Intl.DateTimeFormat} The formatter instance.
|
|
76
76
|
*/
|
|
77
77
|
export function makeFormatter(locale, options) {
|
|
78
78
|
return new Intl.DateTimeFormat(locale, {
|
package/src/formatter/format.js
CHANGED
|
@@ -5,9 +5,9 @@ import { getDayPeriods, getDays, getEras, getMonths, getNumbers } from './values
|
|
|
5
5
|
* Formats a day as a locale string.
|
|
6
6
|
* @param {string} locale The locale.
|
|
7
7
|
* @param {number} day The day to format (0-6).
|
|
8
|
-
* @param {string} [type=long] The formatting type.
|
|
8
|
+
* @param {string} [type='long'] The formatting type.
|
|
9
9
|
* @param {boolean} [standalone=true] Whether the value is standalone.
|
|
10
|
-
* @
|
|
10
|
+
* @returns {string} The formatted string.
|
|
11
11
|
*/
|
|
12
12
|
export function formatDay(locale, day, type = 'long', standalone = true) {
|
|
13
13
|
return getDays(locale, type, standalone)[day];
|
|
@@ -17,8 +17,8 @@ export function formatDay(locale, day, type = 'long', standalone = true) {
|
|
|
17
17
|
* Formats a day period as a locale string.
|
|
18
18
|
* @param {string} locale The locale.
|
|
19
19
|
* @param {number} period The day-period index to format. (0-1)
|
|
20
|
-
* @param {string} [type=long] The formatting type.
|
|
21
|
-
* @
|
|
20
|
+
* @param {string} [type='long'] The formatting type.
|
|
21
|
+
* @returns {string} The formatted string.
|
|
22
22
|
*/
|
|
23
23
|
export function formatDayPeriod(locale, period, type = 'long') {
|
|
24
24
|
return getDayPeriods(locale, type)[period];
|
|
@@ -28,8 +28,8 @@ export function formatDayPeriod(locale, period, type = 'long') {
|
|
|
28
28
|
* Formats an era as a locale string.
|
|
29
29
|
* @param {string} locale The locale.
|
|
30
30
|
* @param {number} era The era index to format. (0-1)
|
|
31
|
-
* @param {string} [type=long] The formatting type.
|
|
32
|
-
* @
|
|
31
|
+
* @param {string} [type='long'] The formatting type.
|
|
32
|
+
* @returns {string} The formatted string.
|
|
33
33
|
*/
|
|
34
34
|
export function formatEra(locale, era, type = 'long') {
|
|
35
35
|
return getEras(locale, type)[era];
|
|
@@ -39,9 +39,9 @@ export function formatEra(locale, era, type = 'long') {
|
|
|
39
39
|
* Formats a month as a locale string.
|
|
40
40
|
* @param {string} locale The locale.
|
|
41
41
|
* @param {number} month The month to format (1-12).
|
|
42
|
-
* @param {string} [type=long] The formatting type.
|
|
42
|
+
* @param {string} [type='long'] The formatting type.
|
|
43
43
|
* @param {boolean} [standalone=true] Whether the value is standalone.
|
|
44
|
-
* @
|
|
44
|
+
* @returns {string} The formatted string.
|
|
45
45
|
*/
|
|
46
46
|
export function formatMonth(locale, month, type = 'long', standalone = true) {
|
|
47
47
|
return getMonths(locale, type, standalone)[month - 1];
|
|
@@ -52,7 +52,7 @@ export function formatMonth(locale, month, type = 'long', standalone = true) {
|
|
|
52
52
|
* @param {string} locale The locale.
|
|
53
53
|
* @param {number} number The number to format.
|
|
54
54
|
* @param {number} [padding=0] The amount of padding to use.
|
|
55
|
-
* @
|
|
55
|
+
* @returns {string} The formatted string.
|
|
56
56
|
*/
|
|
57
57
|
export function formatNumber(locale, number, padding = 0) {
|
|
58
58
|
const numbers = getNumbers(locale);
|
|
@@ -67,7 +67,7 @@ export function formatNumber(locale, number, padding = 0) {
|
|
|
67
67
|
* @param {boolean} [useColon=true] Whether to use a colon separator.
|
|
68
68
|
* @param {boolean} [optionalMinutes=false] Whether minutes are optional.
|
|
69
69
|
* @param {boolean} [includeSeconds=true] Whether seconds are included.
|
|
70
|
-
* @
|
|
70
|
+
* @returns {string} The formatted offset string.
|
|
71
71
|
*/
|
|
72
72
|
export function formatOffset(offset, useColon = true, optionalMinutes = false, includeSeconds = true) {
|
|
73
73
|
const absoluteSeconds = Math.abs(offset * 60);
|
|
@@ -102,7 +102,7 @@ export function formatOffset(offset, useColon = true, optionalMinutes = false, i
|
|
|
102
102
|
* @param {string} locale The locale.
|
|
103
103
|
* @param {number} amount The amount of duration.
|
|
104
104
|
* @param {string} unit The time unit.
|
|
105
|
-
* @
|
|
105
|
+
* @returns {string} The relative duration.
|
|
106
106
|
*/
|
|
107
107
|
export function formatRelative(locale, amount, unit) {
|
|
108
108
|
const relativeFormatter = getRelativeFormatter(locale);
|
|
@@ -119,8 +119,8 @@ export function formatRelative(locale, amount, unit) {
|
|
|
119
119
|
* @param {string} locale The locale.
|
|
120
120
|
* @param {number} timestamp The timestamp to use.
|
|
121
121
|
* @param {string} timeZone The time zone to format.
|
|
122
|
-
* @param {string} [type=long] The formatting type.
|
|
123
|
-
* @
|
|
122
|
+
* @param {string} [type='long'] The formatting type.
|
|
123
|
+
* @returns {string} The formatted string.
|
|
124
124
|
*/
|
|
125
125
|
export function formatTimeZoneName(locale, timestamp, timeZone, type = 'long') {
|
|
126
126
|
return makeFormatter(locale, { second: 'numeric', timeZone, timeZoneName: type })
|
package/src/formatter/locale.js
CHANGED
|
@@ -6,7 +6,7 @@ import { minDaysInFirstWeek, weekStart } from './locales.js';
|
|
|
6
6
|
* @param {object} data The generated locale data.
|
|
7
7
|
* @param {string[]} candidates The locale candidates.
|
|
8
8
|
* @param {number} fallback The fallback value.
|
|
9
|
-
* @
|
|
9
|
+
* @returns {number} The locale value.
|
|
10
10
|
*/
|
|
11
11
|
function generatedValue(data, candidates, fallback) {
|
|
12
12
|
for (const candidate of candidates) {
|
|
@@ -23,7 +23,7 @@ function generatedValue(data, candidates, fallback) {
|
|
|
23
23
|
/**
|
|
24
24
|
* Gets generated-data candidates for a locale.
|
|
25
25
|
* @param {Intl.Locale} locale The locale.
|
|
26
|
-
* @
|
|
26
|
+
* @returns {string[]} The locale candidates.
|
|
27
27
|
*/
|
|
28
28
|
function localeCandidates(locale) {
|
|
29
29
|
const localeName = locale.toString().split('-x-', 1)[0];
|
|
@@ -48,7 +48,7 @@ function localeCandidates(locale) {
|
|
|
48
48
|
/**
|
|
49
49
|
* Gets week information for a locale.
|
|
50
50
|
* @param {string} locale The locale.
|
|
51
|
-
* @
|
|
51
|
+
* @returns {{firstDay: number, minimalDays: number}} The week information.
|
|
52
52
|
*/
|
|
53
53
|
export function getWeekInfo(locale) {
|
|
54
54
|
return getData(
|
package/src/formatter/parse.js
CHANGED
|
@@ -5,9 +5,9 @@ import { getDayPeriods, getDays, getEras, getMonths, getNumbers } from './values
|
|
|
5
5
|
* Parses a day from a locale string.
|
|
6
6
|
* @param {string} locale The locale.
|
|
7
7
|
* @param {string} value The value to parse.
|
|
8
|
-
* @param {string} [type=long] The formatting type.
|
|
8
|
+
* @param {string} [type='long'] The formatting type.
|
|
9
9
|
* @param {boolean} [standalone=true] Whether the value is standalone.
|
|
10
|
-
* @
|
|
10
|
+
* @returns {number} The local day of the week (1-7).
|
|
11
11
|
*/
|
|
12
12
|
export function parseDay(locale, value, type = 'long', standalone = true) {
|
|
13
13
|
const day = getDays(locale, type, standalone).indexOf(value);
|
|
@@ -21,8 +21,8 @@ export function parseDay(locale, value, type = 'long', standalone = true) {
|
|
|
21
21
|
* Parses a day period from a locale string.
|
|
22
22
|
* @param {string} locale The locale.
|
|
23
23
|
* @param {string} value The value to parse.
|
|
24
|
-
* @param {string} [type=long] The formatting type.
|
|
25
|
-
* @
|
|
24
|
+
* @param {string} [type='long'] The formatting type.
|
|
25
|
+
* @returns {number} The day period (0-1).
|
|
26
26
|
*/
|
|
27
27
|
export function parseDayPeriod(locale, value, type = 'long') {
|
|
28
28
|
return getDayPeriods(locale, type).indexOf(value);
|
|
@@ -32,8 +32,8 @@ export function parseDayPeriod(locale, value, type = 'long') {
|
|
|
32
32
|
* Parses an era from a locale string.
|
|
33
33
|
* @param {string} locale The locale.
|
|
34
34
|
* @param {string} value The value to parse.
|
|
35
|
-
* @param {string} [type=long] The formatting type.
|
|
36
|
-
* @
|
|
35
|
+
* @param {string} [type='long'] The formatting type.
|
|
36
|
+
* @returns {number} The era (0-1).
|
|
37
37
|
*/
|
|
38
38
|
export function parseEra(locale, value, type = 'long') {
|
|
39
39
|
return getEras(locale, type).indexOf(value);
|
|
@@ -43,9 +43,9 @@ export function parseEra(locale, value, type = 'long') {
|
|
|
43
43
|
* Parses a month from a locale string.
|
|
44
44
|
* @param {string} locale The locale.
|
|
45
45
|
* @param {string} value The value to parse.
|
|
46
|
-
* @param {string} [type=long] The formatting type.
|
|
46
|
+
* @param {string} [type='long'] The formatting type.
|
|
47
47
|
* @param {boolean} [standalone=true] Whether the value is standalone.
|
|
48
|
-
* @
|
|
48
|
+
* @returns {number} The month number (1-12).
|
|
49
49
|
*/
|
|
50
50
|
export function parseMonth(locale, value, type = 'long', standalone = true) {
|
|
51
51
|
return getMonths(locale, type, standalone).indexOf(value) + 1;
|
|
@@ -55,7 +55,7 @@ export function parseMonth(locale, value, type = 'long', standalone = true) {
|
|
|
55
55
|
* Parses locale digits into an ASCII digit string.
|
|
56
56
|
* @param {string} locale The locale.
|
|
57
57
|
* @param {string} value The value to parse.
|
|
58
|
-
* @
|
|
58
|
+
* @returns {string} The parsed ASCII digit string.
|
|
59
59
|
*/
|
|
60
60
|
export function parseNumberString(locale, value) {
|
|
61
61
|
const numbers = getNumbers(locale);
|
|
@@ -66,7 +66,7 @@ export function parseNumberString(locale, value) {
|
|
|
66
66
|
* Parses a number from a locale number string.
|
|
67
67
|
* @param {string} locale The locale.
|
|
68
68
|
* @param {string} value The value to parse.
|
|
69
|
-
* @
|
|
69
|
+
* @returns {number} The parsed number.
|
|
70
70
|
*/
|
|
71
71
|
export function parseNumber(locale, value) {
|
|
72
72
|
return parseInt(
|
package/src/formatter/utility.js
CHANGED
|
@@ -4,7 +4,7 @@ import { numberRegExp } from './values.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Decodes a quoted ICU format literal.
|
|
6
6
|
* @param {string} literal The literal to decode.
|
|
7
|
-
* @
|
|
7
|
+
* @returns {string} The decoded literal.
|
|
8
8
|
*/
|
|
9
9
|
export function decodeLiteral(literal) {
|
|
10
10
|
return literal === `''` ?
|
|
@@ -15,7 +15,7 @@ export function decodeLiteral(literal) {
|
|
|
15
15
|
/**
|
|
16
16
|
* Gets the formatting type from the component token length.
|
|
17
17
|
* @param {number} length The component token length.
|
|
18
|
-
* @
|
|
18
|
+
* @returns {string} The formatting type.
|
|
19
19
|
*/
|
|
20
20
|
export function getType(length) {
|
|
21
21
|
switch (length) {
|
|
@@ -35,7 +35,7 @@ export function getType(length) {
|
|
|
35
35
|
* @param {number} length The token length.
|
|
36
36
|
* @param {string} locale The parsing locale.
|
|
37
37
|
* @param {boolean} previousNumeric Whether the previous token was an adjacent numeric token.
|
|
38
|
-
* @
|
|
38
|
+
* @returns {{numeric: boolean, source: string}} The token RegExp data.
|
|
39
39
|
*/
|
|
40
40
|
export function getTokenRegExp(source, nextSource, length, locale, previousNumeric) {
|
|
41
41
|
const numberSource = numberRegExp(locale);
|
|
@@ -53,7 +53,7 @@ export function getTokenRegExp(source, nextSource, length, locale, previousNumer
|
|
|
53
53
|
/**
|
|
54
54
|
* Gets the locale's minimum days in the first week of the year.
|
|
55
55
|
* @param {string} locale The locale.
|
|
56
|
-
* @
|
|
56
|
+
* @returns {number} The minimum day count.
|
|
57
57
|
*/
|
|
58
58
|
export function minimumDays(locale) {
|
|
59
59
|
return getWeekInfo(locale).minimalDays;
|
|
@@ -63,7 +63,7 @@ export function minimumDays(locale) {
|
|
|
63
63
|
* Converts a Sunday-based day-of-week value to the locale's week numbering.
|
|
64
64
|
* @param {string} locale The locale.
|
|
65
65
|
* @param {number} day The day of the week. (0 = Sunday, 6 = Saturday)
|
|
66
|
-
* @
|
|
66
|
+
* @returns {number} The local day of the week.
|
|
67
67
|
*/
|
|
68
68
|
export function weekDay(locale, day) {
|
|
69
69
|
return (7 + parseInt(day, 10) - (getWeekInfo(locale).firstDay % 7)) % 7 + 1;
|
package/src/formatter/values.js
CHANGED
|
@@ -8,8 +8,8 @@ import { valuesRegExp } from './../helpers.js';
|
|
|
8
8
|
/**
|
|
9
9
|
* Gets cached localized day-period labels.
|
|
10
10
|
* @param {string} locale The locale.
|
|
11
|
-
* @param {string} [type=long] The formatting type.
|
|
12
|
-
* @
|
|
11
|
+
* @param {string} [type='long'] The formatting type.
|
|
12
|
+
* @returns {string[]} The localized day-period labels.
|
|
13
13
|
*/
|
|
14
14
|
export function getDayPeriods(locale, type = 'long') {
|
|
15
15
|
return getData(
|
|
@@ -30,9 +30,9 @@ export function getDayPeriods(locale, type = 'long') {
|
|
|
30
30
|
/**
|
|
31
31
|
* Gets cached localized weekday labels.
|
|
32
32
|
* @param {string} locale The locale.
|
|
33
|
-
* @param {string} [type=long] The formatting type.
|
|
33
|
+
* @param {string} [type='long'] The formatting type.
|
|
34
34
|
* @param {boolean} [standalone=true] Whether the values are standalone.
|
|
35
|
-
* @
|
|
35
|
+
* @returns {string[]} The localized weekday labels.
|
|
36
36
|
*/
|
|
37
37
|
export function getDays(locale, type = 'long', standalone = true) {
|
|
38
38
|
return getData(
|
|
@@ -62,8 +62,8 @@ export function getDays(locale, type = 'long', standalone = true) {
|
|
|
62
62
|
/**
|
|
63
63
|
* Gets cached localized era labels.
|
|
64
64
|
* @param {string} locale The locale.
|
|
65
|
-
* @param {string} [type=long] The formatting type.
|
|
66
|
-
* @
|
|
65
|
+
* @param {string} [type='long'] The formatting type.
|
|
66
|
+
* @returns {string[]} The localized era labels.
|
|
67
67
|
*/
|
|
68
68
|
export function getEras(locale, type = 'long') {
|
|
69
69
|
return getData(
|
|
@@ -84,9 +84,9 @@ export function getEras(locale, type = 'long') {
|
|
|
84
84
|
/**
|
|
85
85
|
* Gets cached localized month labels.
|
|
86
86
|
* @param {string} locale The locale.
|
|
87
|
-
* @param {string} [type=long] The formatting type.
|
|
87
|
+
* @param {string} [type='long'] The formatting type.
|
|
88
88
|
* @param {boolean} [standalone=true] Whether the values are standalone.
|
|
89
|
-
* @
|
|
89
|
+
* @returns {string[]} The localized month labels.
|
|
90
90
|
*/
|
|
91
91
|
export function getMonths(locale, type = 'long', standalone = true) {
|
|
92
92
|
return getData(
|
|
@@ -116,7 +116,7 @@ export function getMonths(locale, type = 'long', standalone = true) {
|
|
|
116
116
|
/**
|
|
117
117
|
* Gets cached localized digit glyphs.
|
|
118
118
|
* @param {string} locale The locale.
|
|
119
|
-
* @
|
|
119
|
+
* @returns {string[]} The localized digit glyphs.
|
|
120
120
|
*/
|
|
121
121
|
export function getNumbers(locale) {
|
|
122
122
|
return getData(
|
|
@@ -136,7 +136,7 @@ export function getNumbers(locale) {
|
|
|
136
136
|
* Gets the RegExp for the number values.
|
|
137
137
|
* @param {string} locale The locale.
|
|
138
138
|
* @param {number|null} [length=null] The exact number of digits to match.
|
|
139
|
-
* @
|
|
139
|
+
* @returns {string} The number values RegExp.
|
|
140
140
|
*/
|
|
141
141
|
export function numberRegExp(locale, length = null) {
|
|
142
142
|
const quantifier = length === null ?
|
package/src/helpers.js
CHANGED
|
@@ -10,7 +10,7 @@ import { diffMethods, thresholds } from './vars.js';
|
|
|
10
10
|
/**
|
|
11
11
|
* Escapes a string for safe use inside a RegExp source.
|
|
12
12
|
* @param {string} value The string to escape.
|
|
13
|
-
* @
|
|
13
|
+
* @returns {string} The escaped string.
|
|
14
14
|
*/
|
|
15
15
|
function escapeRegExp(value) {
|
|
16
16
|
return value.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&');
|
|
@@ -19,7 +19,7 @@ function escapeRegExp(value) {
|
|
|
19
19
|
/**
|
|
20
20
|
* Gets a stable day number from a DateTime's local calendar fields.
|
|
21
21
|
* @param {DateTime} date The DateTime.
|
|
22
|
-
* @
|
|
22
|
+
* @returns {number} The local calendar day number.
|
|
23
23
|
*/
|
|
24
24
|
function calendarDay(date) {
|
|
25
25
|
const calendarDate = new Date(0);
|
|
@@ -34,7 +34,7 @@ function calendarDay(date) {
|
|
|
34
34
|
* @param {DateTime} other The DateTime to compare to.
|
|
35
35
|
* @param {'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second'} timeUnit The time unit to compare in.
|
|
36
36
|
* @param {boolean} [relative=true] Whether to use relative boundaries when calculating the difference.
|
|
37
|
-
* @
|
|
37
|
+
* @returns {number} The difference between the dates in the given time unit.
|
|
38
38
|
*/
|
|
39
39
|
export function calculateDiff(date, other, timeUnit, relative = true) {
|
|
40
40
|
other = other.withTimeZone(date.getTimeZone());
|
|
@@ -147,7 +147,7 @@ export function calculateDiff(date, other, timeUnit, relative = true) {
|
|
|
147
147
|
* Gets the RegExp for a list of string values.
|
|
148
148
|
* Longer values are matched first to avoid prefix collisions.
|
|
149
149
|
* @param {string[]} values The values to include in the RegExp.
|
|
150
|
-
* @
|
|
150
|
+
* @returns {string} The values RegExp.
|
|
151
151
|
*/
|
|
152
152
|
export function valuesRegExp(values) {
|
|
153
153
|
return values.slice()
|
|
@@ -163,7 +163,7 @@ export function valuesRegExp(values) {
|
|
|
163
163
|
* @param {number} amount The amount to compensate.
|
|
164
164
|
* @param {boolean} [compensate=true] Whether to compensate the amount.
|
|
165
165
|
* @param {number} [compensation=1] The compensation offset.
|
|
166
|
-
* @
|
|
166
|
+
* @returns {number} The compensated amount.
|
|
167
167
|
*/
|
|
168
168
|
function compensateDiff(date, other, amount, compensate = true, compensation = 1) {
|
|
169
169
|
if (amount > 0) {
|
|
@@ -187,7 +187,7 @@ function compensateDiff(date, other, amount, compensate = true, compensation = 1
|
|
|
187
187
|
* Gets the biggest difference between two dates.
|
|
188
188
|
* @param {DateTime} date The DateTime.
|
|
189
189
|
* @param {DateTime} [other] The DateTime to compare to.
|
|
190
|
-
* @
|
|
190
|
+
* @returns {[number, string]} The biggest difference (amount and time unit).
|
|
191
191
|
*/
|
|
192
192
|
export function getBiggestDiff(date, other) {
|
|
193
193
|
let lastResult;
|
|
@@ -219,7 +219,7 @@ export function getBiggestDiff(date, other) {
|
|
|
219
219
|
/**
|
|
220
220
|
* Gets the offset for a DateTime.
|
|
221
221
|
* @param {DateTime} date The DateTime.
|
|
222
|
-
* @
|
|
222
|
+
* @returns {number} The offset.
|
|
223
223
|
*/
|
|
224
224
|
export function getOffset(date) {
|
|
225
225
|
const timeZone = date.getTimeZone();
|
|
@@ -259,7 +259,7 @@ export function getOffset(date) {
|
|
|
259
259
|
/**
|
|
260
260
|
* Gets the number of milliseconds since the UNIX epoch (offset to timeZone).
|
|
261
261
|
* @param {DateTime} date The DateTime.
|
|
262
|
-
* @
|
|
262
|
+
* @returns {number} The number of milliseconds since the UNIX epoch (offset to timeZone).
|
|
263
263
|
*/
|
|
264
264
|
export function getOffsetTime(date) {
|
|
265
265
|
return date.getTime() - (date.getTimeZoneOffset() * 60000);
|
|
@@ -284,7 +284,7 @@ export function parseCompare(formatString, dateString) {
|
|
|
284
284
|
/**
|
|
285
285
|
* Parses a supported unzoned ISO string as a neutral wall-clock timestamp.
|
|
286
286
|
* @param {string} dateString The date string to parse.
|
|
287
|
-
* @
|
|
287
|
+
* @returns {number|null} The timestamp, or null if the shape is not supported.
|
|
288
288
|
*/
|
|
289
289
|
export function parseLocalTimestamp(dateString) {
|
|
290
290
|
const match =
|
|
@@ -314,7 +314,7 @@ export function parseLocalTimestamp(dateString) {
|
|
|
314
314
|
|
|
315
315
|
/**
|
|
316
316
|
* Generates methods for parsing a date.
|
|
317
|
-
* @
|
|
317
|
+
* @returns {Record<string, {get: Function, set: Function}>} An object containing date parsing methods.
|
|
318
318
|
*/
|
|
319
319
|
export function parseFactory() {
|
|
320
320
|
let isPM = false;
|
|
@@ -421,7 +421,7 @@ export function parseFactory() {
|
|
|
421
421
|
* @param {DateTime} date The DateTime.
|
|
422
422
|
* @param {number} time The number of milliseconds since the UNIX epoch (offset to timeZone).
|
|
423
423
|
* @param {number} [direction=1] The direction to resolve a gap.
|
|
424
|
-
* @
|
|
424
|
+
* @returns {DateTime} A new DateTime instance.
|
|
425
425
|
*/
|
|
426
426
|
export function setOffsetTime(date, time, direction = 1) {
|
|
427
427
|
const newDate = date.withTime(
|