date-vir 0.2.4 → 0.2.6
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/cjs/full-date/primitive-conversions.js +13 -2
- package/dist/esm/full-date/calculate-relative-date.js +3 -7
- package/dist/esm/full-date/combine-dates.js +5 -9
- package/dist/esm/full-date/create-full-date.js +21 -29
- package/dist/esm/full-date/date-like.js +1 -2
- package/dist/esm/full-date/format-presets.js +24 -27
- package/dist/esm/full-date/full-date-shape.js +9 -12
- package/dist/esm/full-date/is-valid-full-date.js +9 -14
- package/dist/esm/full-date/luxon-date-time-conversion.js +5 -10
- package/dist/esm/full-date/parsing.js +10 -15
- package/dist/esm/full-date/primitive-conversions.js +29 -26
- package/dist/esm/full-date/string-format-types.js +1 -2
- package/dist/esm/index.js +15 -31
- package/dist/esm/locales.js +2 -5
- package/dist/esm/timezone/timezone-checks.js +4 -9
- package/dist/esm/timezone/timezone-names.js +1 -4
- package/dist/esm/timezone/timezones.js +5 -8
- package/package.json +1 -1
|
@@ -22,13 +22,21 @@ function toIsoString(fullDate) {
|
|
|
22
22
|
return isoString;
|
|
23
23
|
}
|
|
24
24
|
exports.toIsoString = toIsoString;
|
|
25
|
+
/**
|
|
26
|
+
* Chromium has a weird behavior where the "NARROW NO-BREAK SPACE" character (code 8239) is used
|
|
27
|
+
* instead of a space (code 32) before AM/PM.
|
|
28
|
+
*/
|
|
29
|
+
function fixChromiumSpace(original) {
|
|
30
|
+
return original.replace(new RegExp(String.fromCharCode(8239), 'g'), ' ');
|
|
31
|
+
}
|
|
25
32
|
/** Converts the given FullDate into a string in the user's locale, or the given localeOverride. */
|
|
26
33
|
function toLocaleString(fullDate, formatOptions) {
|
|
27
|
-
|
|
34
|
+
const localeString = (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).toLocaleString({
|
|
28
35
|
...formatOptions,
|
|
29
36
|
}, {
|
|
30
37
|
locale: formatOptions?.locale ?? locales_1.userLocale,
|
|
31
38
|
});
|
|
39
|
+
return fixChromiumSpace(localeString);
|
|
32
40
|
}
|
|
33
41
|
exports.toLocaleString = toLocaleString;
|
|
34
42
|
/**
|
|
@@ -39,7 +47,10 @@ exports.toLocaleString = toLocaleString;
|
|
|
39
47
|
* already has many formatting options.
|
|
40
48
|
*/
|
|
41
49
|
function toFormattedString(fullDate, format, localeOverride = locales_1.userLocale) {
|
|
42
|
-
|
|
50
|
+
const formattedString = (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate)
|
|
51
|
+
.toFormat(format, { locale: localeOverride })
|
|
52
|
+
.replace(/ /g, ' ');
|
|
53
|
+
return fixChromiumSpace(formattedString);
|
|
43
54
|
}
|
|
44
55
|
exports.toFormattedString = toFormattedString;
|
|
45
56
|
function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
|
|
5
|
-
function calculateRelativeDate(fullDate, relativeCalculation) {
|
|
6
|
-
return (0, luxon_date_time_conversion_1.parseLuxonDateTime)((0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).plus(relativeCalculation));
|
|
1
|
+
import { parseLuxonDateTime, toLuxonDateTime } from './luxon-date-time-conversion';
|
|
2
|
+
export function calculateRelativeDate(fullDate, relativeCalculation) {
|
|
3
|
+
return parseLuxonDateTime(toLuxonDateTime(fullDate).plus(relativeCalculation));
|
|
7
4
|
}
|
|
8
|
-
exports.calculateRelativeDate = calculateRelativeDate;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const full_date_shape_1 = require("./full-date-shape");
|
|
6
|
-
function combineDateParts(maybeDateParts) {
|
|
7
|
-
const timePart = (0, object_shape_tester_1.isValidShape)(maybeDateParts.time, full_date_shape_1.timePartShape, {
|
|
1
|
+
import { isValidShape } from 'object-shape-tester';
|
|
2
|
+
import { FullDatePartEnum, datePartShape, timePartShape, } from './full-date-shape';
|
|
3
|
+
export function combineDateParts(maybeDateParts) {
|
|
4
|
+
const timePart = isValidShape(maybeDateParts.time, timePartShape, {
|
|
8
5
|
allowExtraKeys: true,
|
|
9
6
|
})
|
|
10
7
|
? {
|
|
@@ -15,7 +12,7 @@ function combineDateParts(maybeDateParts) {
|
|
|
15
12
|
timezone: maybeDateParts.time.timezone,
|
|
16
13
|
}
|
|
17
14
|
: undefined;
|
|
18
|
-
const datePart =
|
|
15
|
+
const datePart = isValidShape(maybeDateParts.date, datePartShape, {
|
|
19
16
|
allowExtraKeys: true,
|
|
20
17
|
})
|
|
21
18
|
? {
|
|
@@ -42,4 +39,3 @@ function combineDateParts(maybeDateParts) {
|
|
|
42
39
|
}
|
|
43
40
|
return undefined;
|
|
44
41
|
}
|
|
45
|
-
exports.combineDateParts = combineDateParts;
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
|
|
9
|
-
function createFullDateInUserTimezone(dateLike) {
|
|
10
|
-
return createFullDate(dateLike, timezones_1.userTimezone);
|
|
1
|
+
import { isRuntimeTypeOf } from '@augment-vir/common';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
import { userTimezone, utcTimezone } from '../timezone/timezones';
|
|
4
|
+
import { isValidFullDate } from './is-valid-full-date';
|
|
5
|
+
import { parseLuxonDateTime, toLuxonDateTime } from './luxon-date-time-conversion';
|
|
6
|
+
export function createFullDateInUserTimezone(dateLike) {
|
|
7
|
+
return createFullDate(dateLike, userTimezone);
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return createFullDate(dateLike, timezones_1.utcTimezone);
|
|
9
|
+
export function createUtcFullDate(dateLike) {
|
|
10
|
+
return createFullDate(dateLike, utcTimezone);
|
|
15
11
|
}
|
|
16
|
-
exports.createUtcFullDate = createUtcFullDate;
|
|
17
12
|
/**
|
|
18
13
|
* Parses the given dateLike and then reads the fullDate properties from that parsed value as if it
|
|
19
14
|
* were in the given timezone.
|
|
20
15
|
*/
|
|
21
|
-
function createFullDate(
|
|
16
|
+
export function createFullDate(
|
|
22
17
|
/** The original date representation to be converted into a FullDate. */
|
|
23
18
|
dateLike,
|
|
24
19
|
/** The timezone that this date/time is meant for / originated from. */
|
|
@@ -27,44 +22,41 @@ timezone) {
|
|
|
27
22
|
if (!dateTime || !dateTime.isValid) {
|
|
28
23
|
throw new Error(`Failed to parse date input '${dateLike}'`);
|
|
29
24
|
}
|
|
30
|
-
return
|
|
25
|
+
return parseLuxonDateTime(dateTime);
|
|
31
26
|
}
|
|
32
|
-
exports.createFullDate = createFullDate;
|
|
33
27
|
/**
|
|
34
28
|
* Creates and returns a new FullDate object with its values shifted to be the same original time
|
|
35
29
|
* but represented in a new timezone.
|
|
36
30
|
*/
|
|
37
|
-
function toNewTimezone(fullDate, timezone) {
|
|
31
|
+
export function toNewTimezone(fullDate, timezone) {
|
|
38
32
|
if (fullDate.timezone === timezone) {
|
|
39
33
|
return fullDate;
|
|
40
34
|
}
|
|
41
35
|
return createFullDate(fullDate, timezone);
|
|
42
36
|
}
|
|
43
|
-
exports.toNewTimezone = toNewTimezone;
|
|
44
37
|
function convertDateLikeToLuxonDateTime(dateLike, timezone) {
|
|
45
|
-
if (
|
|
46
|
-
dateLike =
|
|
38
|
+
if (isValidFullDate(dateLike)) {
|
|
39
|
+
dateLike = toLuxonDateTime(dateLike).toMillis();
|
|
47
40
|
}
|
|
48
|
-
if (
|
|
41
|
+
if (DateTime.isDateTime(dateLike)) {
|
|
49
42
|
return dateLike.setZone(timezone);
|
|
50
43
|
}
|
|
51
|
-
else if (
|
|
52
|
-
return
|
|
44
|
+
else if (isRuntimeTypeOf(dateLike, 'number')) {
|
|
45
|
+
return DateTime.fromMillis(dateLike, { zone: utcTimezone }).setZone(timezone);
|
|
53
46
|
}
|
|
54
|
-
else if (
|
|
55
|
-
const dateTime =
|
|
47
|
+
else if (isRuntimeTypeOf(dateLike, 'string')) {
|
|
48
|
+
const dateTime = DateTime.fromISO(dateLike, { zone: timezone });
|
|
56
49
|
if (!dateTime.isValid) {
|
|
57
50
|
throw new Error(`Failed to parse date string '${dateLike}': unexpected string format. Please use parseStringToFullDate instead to have more control over the parsing format.`);
|
|
58
51
|
}
|
|
59
52
|
return dateTime;
|
|
60
53
|
}
|
|
61
54
|
else if (dateLike instanceof Date) {
|
|
62
|
-
const dateTime =
|
|
55
|
+
const dateTime = DateTime.fromJSDate(dateLike);
|
|
63
56
|
return dateTime.setZone(timezone);
|
|
64
57
|
}
|
|
65
58
|
return undefined;
|
|
66
59
|
}
|
|
67
|
-
function getNowFullDate(timezone) {
|
|
60
|
+
export function getNowFullDate(timezone) {
|
|
68
61
|
return createFullDate(Date.now(), timezone);
|
|
69
62
|
}
|
|
70
|
-
exports.getNowFullDate = getNowFullDate;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatPresets = void 0;
|
|
4
|
-
const luxon_1 = require("luxon");
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
5
2
|
/**
|
|
6
3
|
* Format preset re-exported from luxon to be used with toLocaleString. To see examples of all
|
|
7
4
|
* presets, go here: https://moment.github.io/luxon/#/formatting?id=presets
|
|
8
5
|
*/
|
|
9
|
-
|
|
10
|
-
DateShort:
|
|
11
|
-
DateMed:
|
|
12
|
-
DateMedWithWeekday:
|
|
13
|
-
DateFull:
|
|
14
|
-
DateHuge:
|
|
15
|
-
TimeSimple:
|
|
16
|
-
TimeWithSeconds:
|
|
17
|
-
TimeWithShortOffset:
|
|
18
|
-
TimeWithLongOffset:
|
|
19
|
-
Time24Simple:
|
|
20
|
-
Time24WithSeconds:
|
|
21
|
-
Time24WithShortOffset:
|
|
22
|
-
Time24WithLongOffset:
|
|
23
|
-
DatetimeShort:
|
|
24
|
-
DatetimeShortWithSeconds:
|
|
25
|
-
DatetimeMed:
|
|
26
|
-
DatetimeMedWithSeconds:
|
|
27
|
-
DatetimeMedWithWeekday:
|
|
28
|
-
DatetimeFull:
|
|
29
|
-
DatetimeFullWithSeconds:
|
|
30
|
-
DatetimeHuge:
|
|
31
|
-
DatetimeHugeWithSeconds:
|
|
6
|
+
export const formatPresets = {
|
|
7
|
+
DateShort: DateTime.DATE_SHORT,
|
|
8
|
+
DateMed: DateTime.DATE_MED,
|
|
9
|
+
DateMedWithWeekday: DateTime.DATE_MED_WITH_WEEKDAY,
|
|
10
|
+
DateFull: DateTime.DATE_FULL,
|
|
11
|
+
DateHuge: DateTime.DATE_HUGE,
|
|
12
|
+
TimeSimple: DateTime.TIME_SIMPLE,
|
|
13
|
+
TimeWithSeconds: DateTime.TIME_WITH_SECONDS,
|
|
14
|
+
TimeWithShortOffset: DateTime.TIME_WITH_SHORT_OFFSET,
|
|
15
|
+
TimeWithLongOffset: DateTime.TIME_WITH_LONG_OFFSET,
|
|
16
|
+
Time24Simple: DateTime.TIME_24_SIMPLE,
|
|
17
|
+
Time24WithSeconds: DateTime.TIME_24_WITH_SECONDS,
|
|
18
|
+
Time24WithShortOffset: DateTime.TIME_24_WITH_SHORT_OFFSET,
|
|
19
|
+
Time24WithLongOffset: DateTime.TIME_24_WITH_LONG_OFFSET,
|
|
20
|
+
DatetimeShort: DateTime.DATETIME_SHORT,
|
|
21
|
+
DatetimeShortWithSeconds: DateTime.DATETIME_SHORT_WITH_SECONDS,
|
|
22
|
+
DatetimeMed: DateTime.DATETIME_MED,
|
|
23
|
+
DatetimeMedWithSeconds: DateTime.DATETIME_MED_WITH_SECONDS,
|
|
24
|
+
DatetimeMedWithWeekday: DateTime.DATETIME_MED_WITH_WEEKDAY,
|
|
25
|
+
DatetimeFull: DateTime.DATETIME_FULL,
|
|
26
|
+
DatetimeFullWithSeconds: DateTime.DATETIME_FULL_WITH_SECONDS,
|
|
27
|
+
DatetimeHuge: DateTime.DATETIME_HUGE,
|
|
28
|
+
DatetimeHugeWithSeconds: DateTime.DATETIME_HUGE_WITH_SECONDS,
|
|
32
29
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const object_shape_tester_1 = require("object-shape-tester");
|
|
5
|
-
const timezones_1 = require("../timezone/timezones");
|
|
6
|
-
var FullDatePartEnum;
|
|
1
|
+
import { and, defineShape } from 'object-shape-tester';
|
|
2
|
+
import { utcTimezone } from '../timezone/timezones';
|
|
3
|
+
export var FullDatePartEnum;
|
|
7
4
|
(function (FullDatePartEnum) {
|
|
8
5
|
FullDatePartEnum["Date"] = "date";
|
|
9
6
|
FullDatePartEnum["Time"] = "time";
|
|
10
|
-
})(FullDatePartEnum
|
|
11
|
-
|
|
7
|
+
})(FullDatePartEnum || (FullDatePartEnum = {}));
|
|
8
|
+
export const timePartShape = defineShape({
|
|
12
9
|
/** Hour of the day in 24 time: 0-23 */
|
|
13
10
|
hour: 14,
|
|
14
11
|
/** Minute of the hour: 0-59 */
|
|
@@ -18,9 +15,9 @@ exports.timePartShape = (0, object_shape_tester_1.defineShape)({
|
|
|
18
15
|
/** Millisecond of the second: 0-999 */
|
|
19
16
|
millisecond: 870,
|
|
20
17
|
/** The timezone that this date/time is meant for / originated from. */
|
|
21
|
-
timezone:
|
|
18
|
+
timezone: utcTimezone,
|
|
22
19
|
});
|
|
23
|
-
|
|
20
|
+
export const datePartShape = defineShape({
|
|
24
21
|
/**
|
|
25
22
|
* The full, four digit year.
|
|
26
23
|
*
|
|
@@ -33,6 +30,6 @@ exports.datePartShape = (0, object_shape_tester_1.defineShape)({
|
|
|
33
30
|
/** A day of the month: 1-31 depending on the month */
|
|
34
31
|
day: 5,
|
|
35
32
|
/** The timezone that this date/time is meant for / originated from. */
|
|
36
|
-
timezone:
|
|
33
|
+
timezone: utcTimezone,
|
|
37
34
|
});
|
|
38
|
-
|
|
35
|
+
export const fullDateShape = defineShape(and(datePartShape, timePartShape));
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function assertIsValidFullDate(input) {
|
|
9
|
-
(0, object_shape_tester_1.assertValidShape)(input, full_date_shape_1.fullDateShape);
|
|
10
|
-
(0, timezone_checks_1.assertValidTimezone)(input.timezone);
|
|
1
|
+
import { assertValidShape } from 'object-shape-tester';
|
|
2
|
+
import { assertValidTimezone } from '../timezone/timezone-checks';
|
|
3
|
+
import { fullDateShape } from './full-date-shape';
|
|
4
|
+
import { toLuxonDateTime } from './luxon-date-time-conversion';
|
|
5
|
+
export function assertIsValidFullDate(input) {
|
|
6
|
+
assertValidShape(input, fullDateShape);
|
|
7
|
+
assertValidTimezone(input.timezone);
|
|
11
8
|
/** Check that the input can be converted to a luxon date correctly. */
|
|
12
|
-
|
|
9
|
+
toLuxonDateTime(input);
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
function isValidFullDate(input) {
|
|
11
|
+
export function isValidFullDate(input) {
|
|
16
12
|
try {
|
|
17
13
|
assertIsValidFullDate(input);
|
|
18
14
|
return true;
|
|
@@ -21,4 +17,3 @@ function isValidFullDate(input) {
|
|
|
21
17
|
return false;
|
|
22
18
|
}
|
|
23
19
|
}
|
|
24
|
-
exports.isValidFullDate = isValidFullDate;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseLuxonDateTime = exports.toLuxonDateTime = void 0;
|
|
4
|
-
const common_1 = require("@augment-vir/common");
|
|
5
|
-
const luxon_1 = require("luxon");
|
|
1
|
+
import { omitObjectKeys } from '@augment-vir/common';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
6
3
|
/**
|
|
7
4
|
* Converts a FullDate object into a Luxon DateTime library. This is only needed if you need complex
|
|
8
5
|
* operations on dates. It does, however, internally power a lot of the date-vir functionality as it
|
|
9
6
|
* uses the Luxon library for conversions between timezones.
|
|
10
7
|
*/
|
|
11
|
-
function toLuxonDateTime(fullDateInput) {
|
|
12
|
-
const dateTime =
|
|
8
|
+
export function toLuxonDateTime(fullDateInput) {
|
|
9
|
+
const dateTime = DateTime.fromObject(omitObjectKeys(fullDateInput, ['timezone']), {
|
|
13
10
|
zone: fullDateInput.timezone,
|
|
14
11
|
});
|
|
15
12
|
/** Ignore this edge case in coverage cause idk how to trigger it. */
|
|
@@ -19,13 +16,12 @@ function toLuxonDateTime(fullDateInput) {
|
|
|
19
16
|
}
|
|
20
17
|
return dateTime;
|
|
21
18
|
}
|
|
22
|
-
exports.toLuxonDateTime = toLuxonDateTime;
|
|
23
19
|
/**
|
|
24
20
|
* Convert a Luxon DateTime object into a DateTime object. Used internally inside of date-vir, but
|
|
25
21
|
* could be helpful if you need it. Usually you should prefer using the createFullDate function
|
|
26
22
|
* instead.
|
|
27
23
|
*/
|
|
28
|
-
function parseLuxonDateTime(dateTimeInput) {
|
|
24
|
+
export function parseLuxonDateTime(dateTimeInput) {
|
|
29
25
|
if (!dateTimeInput.isValid) {
|
|
30
26
|
throw new Error(`Invalid input: '${dateTimeInput.toISO()}'`);
|
|
31
27
|
}
|
|
@@ -40,4 +36,3 @@ function parseLuxonDateTime(dateTimeInput) {
|
|
|
40
36
|
timezone: dateTimeInput.zoneName,
|
|
41
37
|
};
|
|
42
38
|
}
|
|
43
|
-
exports.parseLuxonDateTime = parseLuxonDateTime;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const luxon_1 = require("luxon");
|
|
6
|
-
const create_full_date_1 = require("./create-full-date");
|
|
7
|
-
const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
|
|
1
|
+
import { isRuntimeTypeOf } from '@augment-vir/common';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
import { createFullDate } from './create-full-date';
|
|
4
|
+
import { parseLuxonDateTime } from './luxon-date-time-conversion';
|
|
8
5
|
/**
|
|
9
6
|
* Parses any strangely formatted dateString using the given formatString and timezone.
|
|
10
7
|
*
|
|
@@ -14,35 +11,33 @@ const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
|
|
|
14
11
|
* The formatString input is passed to Luxon. All format options are listed here:
|
|
15
12
|
* https://moment.github.io/luxon/#/parsing?id=table-of-tokens
|
|
16
13
|
*/
|
|
17
|
-
function parseStrangeString({ dateString, formatString, timezone, }) {
|
|
14
|
+
export function parseStrangeString({ dateString, formatString, timezone, }) {
|
|
18
15
|
try {
|
|
19
|
-
const dateTime =
|
|
16
|
+
const dateTime = DateTime.fromFormat(dateString, formatString, {
|
|
20
17
|
zone: timezone,
|
|
21
18
|
setZone: true,
|
|
22
19
|
});
|
|
23
|
-
return
|
|
20
|
+
return parseLuxonDateTime(dateTime);
|
|
24
21
|
}
|
|
25
22
|
catch (error) {
|
|
26
23
|
throw new Error(`Failed to parse string '${dateString}' with format '${formatString}'`);
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
exports.parseStrangeString = parseStrangeString;
|
|
30
26
|
/**
|
|
31
27
|
* Read either an HTMLInputElement's value directly, or the value string retrieved from an
|
|
32
28
|
* HTMLInputElement. Handles both type="date" and type="time" <input> elements.
|
|
33
29
|
*/
|
|
34
|
-
function parseInputElementValue(elementOrValue, timezone) {
|
|
30
|
+
export function parseInputElementValue(elementOrValue, timezone) {
|
|
35
31
|
if (!elementOrValue) {
|
|
36
32
|
return undefined;
|
|
37
33
|
}
|
|
38
|
-
const value =
|
|
34
|
+
const value = isRuntimeTypeOf(elementOrValue, 'string')
|
|
39
35
|
? elementOrValue
|
|
40
36
|
: elementOrValue.value;
|
|
41
37
|
try {
|
|
42
|
-
return
|
|
38
|
+
return createFullDate(value, timezone);
|
|
43
39
|
}
|
|
44
40
|
catch (error) {
|
|
45
41
|
return undefined;
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
|
-
exports.parseInputElementValue = parseInputElementValue;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const timezones_1 = require("../timezone/timezones");
|
|
7
|
-
const full_date_shape_1 = require("./full-date-shape");
|
|
8
|
-
const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
|
|
1
|
+
import { getEnumTypedValues } from '@augment-vir/common';
|
|
2
|
+
import { userLocale } from '../locales';
|
|
3
|
+
import { utcTimezone } from '../timezone/timezones';
|
|
4
|
+
import { FullDatePartEnum } from './full-date-shape';
|
|
5
|
+
import { toLuxonDateTime } from './luxon-date-time-conversion';
|
|
9
6
|
/** Convert a FullDate into a unix timestamp with milliseconds. */
|
|
10
|
-
function toTimestamp(fullDate) {
|
|
11
|
-
return
|
|
7
|
+
export function toTimestamp(fullDate) {
|
|
8
|
+
return toLuxonDateTime(fullDate).toMillis();
|
|
12
9
|
}
|
|
13
|
-
exports.toTimestamp = toTimestamp;
|
|
14
10
|
/** Convert a FullDate into an ISO string in UTC; always ends in Z. */
|
|
15
|
-
function toIsoString(fullDate) {
|
|
16
|
-
const isoString =
|
|
11
|
+
export function toIsoString(fullDate) {
|
|
12
|
+
const isoString = toLuxonDateTime(fullDate).setZone(utcTimezone).toISO();
|
|
17
13
|
/** Ignore this edge case in the types and idk how to trigger it. */
|
|
18
14
|
/* c8 ignore next 3 */
|
|
19
15
|
if (!isoString) {
|
|
@@ -21,16 +17,22 @@ function toIsoString(fullDate) {
|
|
|
21
17
|
}
|
|
22
18
|
return isoString;
|
|
23
19
|
}
|
|
24
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Chromium has a weird behavior where the "NARROW NO-BREAK SPACE" character (code 8239) is used
|
|
22
|
+
* instead of a space (code 32) before AM/PM.
|
|
23
|
+
*/
|
|
24
|
+
function fixChromiumSpace(original) {
|
|
25
|
+
return original.replace(new RegExp(String.fromCharCode(8239), 'g'), ' ');
|
|
26
|
+
}
|
|
25
27
|
/** Converts the given FullDate into a string in the user's locale, or the given localeOverride. */
|
|
26
|
-
function toLocaleString(fullDate, formatOptions) {
|
|
27
|
-
|
|
28
|
+
export function toLocaleString(fullDate, formatOptions) {
|
|
29
|
+
const localeString = toLuxonDateTime(fullDate).toLocaleString({
|
|
28
30
|
...formatOptions,
|
|
29
31
|
}, {
|
|
30
|
-
locale: formatOptions?.locale ??
|
|
32
|
+
locale: formatOptions?.locale ?? userLocale,
|
|
31
33
|
});
|
|
34
|
+
return fixChromiumSpace(localeString);
|
|
32
35
|
}
|
|
33
|
-
exports.toLocaleString = toLocaleString;
|
|
34
36
|
/**
|
|
35
37
|
* Provides arbitrary date formatting using Luxon. For full details on the options for the format
|
|
36
38
|
* string input, see https://moment.github.io/luxon/#/formatting?id=table-of-tokens
|
|
@@ -38,12 +40,14 @@ exports.toLocaleString = toLocaleString;
|
|
|
38
40
|
* You probably should **prefer toLocaleString** so your users see the format they expect. It
|
|
39
41
|
* already has many formatting options.
|
|
40
42
|
*/
|
|
41
|
-
function toFormattedString(fullDate, format, localeOverride =
|
|
42
|
-
|
|
43
|
+
export function toFormattedString(fullDate, format, localeOverride = userLocale) {
|
|
44
|
+
const formattedString = toLuxonDateTime(fullDate)
|
|
45
|
+
.toFormat(format, { locale: localeOverride })
|
|
46
|
+
.replace(/ /g, ' ');
|
|
47
|
+
return fixChromiumSpace(formattedString);
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (inputType === full_date_shape_1.FullDatePartEnum.Date) {
|
|
49
|
+
export function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
50
|
+
if (inputType === FullDatePartEnum.Date) {
|
|
47
51
|
if (fullDate.year == undefined) {
|
|
48
52
|
throw new Error(`Tried to create date string but no year was provided.`);
|
|
49
53
|
}
|
|
@@ -60,7 +64,7 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
|
60
64
|
];
|
|
61
65
|
return dateParts.join('-');
|
|
62
66
|
}
|
|
63
|
-
else if (inputType ===
|
|
67
|
+
else if (inputType === FullDatePartEnum.Time) {
|
|
64
68
|
if (includeSeconds && fullDate.second == undefined) {
|
|
65
69
|
throw new Error('Tried to include seconds in the time string but no seconds were provided.');
|
|
66
70
|
}
|
|
@@ -78,7 +82,6 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
|
78
82
|
return timeParts.join(':');
|
|
79
83
|
}
|
|
80
84
|
else {
|
|
81
|
-
throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of FullDatePartEnum or one of ${
|
|
85
|
+
throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of FullDatePartEnum or one of ${getEnumTypedValues(FullDatePartEnum).join(', ')}.`);
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
|
-
exports.toHtmlInputString = toHtmlInputString;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./full-date/calculate-relative-date"), exports);
|
|
18
|
-
__exportStar(require("./full-date/combine-dates"), exports);
|
|
19
|
-
__exportStar(require("./full-date/create-full-date"), exports);
|
|
20
|
-
__exportStar(require("./full-date/date-like"), exports);
|
|
21
|
-
__exportStar(require("./full-date/format-presets"), exports);
|
|
22
|
-
__exportStar(require("./full-date/full-date-shape"), exports);
|
|
23
|
-
__exportStar(require("./full-date/is-valid-full-date"), exports);
|
|
24
|
-
__exportStar(require("./full-date/luxon-date-time-conversion"), exports);
|
|
25
|
-
__exportStar(require("./full-date/parsing"), exports);
|
|
26
|
-
__exportStar(require("./full-date/primitive-conversions"), exports);
|
|
27
|
-
__exportStar(require("./full-date/string-format-types"), exports);
|
|
28
|
-
__exportStar(require("./locales"), exports);
|
|
29
|
-
__exportStar(require("./timezone/timezone-checks"), exports);
|
|
30
|
-
__exportStar(require("./timezone/timezone-names"), exports);
|
|
31
|
-
__exportStar(require("./timezone/timezones"), exports);
|
|
1
|
+
export * from './full-date/calculate-relative-date';
|
|
2
|
+
export * from './full-date/combine-dates';
|
|
3
|
+
export * from './full-date/create-full-date';
|
|
4
|
+
export * from './full-date/date-like';
|
|
5
|
+
export * from './full-date/format-presets';
|
|
6
|
+
export * from './full-date/full-date-shape';
|
|
7
|
+
export * from './full-date/is-valid-full-date';
|
|
8
|
+
export * from './full-date/luxon-date-time-conversion';
|
|
9
|
+
export * from './full-date/parsing';
|
|
10
|
+
export * from './full-date/primitive-conversions';
|
|
11
|
+
export * from './full-date/string-format-types';
|
|
12
|
+
export * from './locales';
|
|
13
|
+
export * from './timezone/timezone-checks';
|
|
14
|
+
export * from './timezone/timezone-names';
|
|
15
|
+
export * from './timezone/timezones';
|
package/dist/esm/locales.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.userLocale = void 0;
|
|
4
|
-
const luxon_1 = require("luxon");
|
|
5
|
-
exports.userLocale = luxon_1.Settings.defaultLocale;
|
|
1
|
+
import { Settings } from 'luxon';
|
|
2
|
+
export const userLocale = Settings.defaultLocale;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidTimezone = exports.assertValidTimezone = void 0;
|
|
4
|
-
const luxon_1 = require("luxon");
|
|
1
|
+
import { Info } from 'luxon';
|
|
5
2
|
/**
|
|
6
3
|
* Asserts that the given timezoneName is a valid timezone name.
|
|
7
4
|
*
|
|
@@ -9,12 +6,11 @@ const luxon_1 = require("luxon");
|
|
|
9
6
|
* because this function uses luxon to check that it is able to generate a date with the given
|
|
10
7
|
* timezone, regardless of whether it's in our typed list or not.
|
|
11
8
|
*/
|
|
12
|
-
function assertValidTimezone(potentialTimezoneName) {
|
|
13
|
-
if (!
|
|
9
|
+
export function assertValidTimezone(potentialTimezoneName) {
|
|
10
|
+
if (!Info.isValidIANAZone(potentialTimezoneName)) {
|
|
14
11
|
throw new Error(`'${potentialTimezoneName}' is not a valid time zone`);
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
|
-
exports.assertValidTimezone = assertValidTimezone;
|
|
18
14
|
/**
|
|
19
15
|
* Checks that the given timezoneName is a valid timezone name.
|
|
20
16
|
*
|
|
@@ -22,7 +18,7 @@ exports.assertValidTimezone = assertValidTimezone;
|
|
|
22
18
|
* because this function uses luxon to check that it is able to generate a date with the given
|
|
23
19
|
* timezone, regardless of whether it's in our typed list or not.
|
|
24
20
|
*/
|
|
25
|
-
function isValidTimezone(potentialTimezoneName) {
|
|
21
|
+
export function isValidTimezone(potentialTimezoneName) {
|
|
26
22
|
try {
|
|
27
23
|
assertValidTimezone(potentialTimezoneName);
|
|
28
24
|
return true;
|
|
@@ -31,4 +27,3 @@ function isValidTimezone(potentialTimezoneName) {
|
|
|
31
27
|
return false;
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
|
-
exports.isValidTimezone = isValidTimezone;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.allTimezoneNames = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* This list was generated from Firefox 106.0.2 (which gave me the longest list out of all the
|
|
6
3
|
* browsers I had immediately available to me at the time) with the following code:
|
|
7
4
|
*
|
|
8
5
|
* Intl.supportedValuesOf('timeZone').map(zone => `'${zone}'`).join(',')
|
|
9
6
|
*/
|
|
10
|
-
|
|
7
|
+
export const allTimezoneNames = [
|
|
11
8
|
'Africa/Abidjan',
|
|
12
9
|
'Africa/Accra',
|
|
13
10
|
'Africa/Addis_Ababa',
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.utcTimezone = exports.userTimezone = exports.timezones = void 0;
|
|
4
|
-
const luxon_1 = require("luxon");
|
|
5
|
-
const timezone_names_1 = require("./timezone-names");
|
|
1
|
+
import { Settings } from 'luxon';
|
|
2
|
+
import { allTimezoneNames } from './timezone-names';
|
|
6
3
|
/** A typed object of all known timezones, as of the writing of this message. */
|
|
7
|
-
|
|
4
|
+
export const timezones = allTimezoneNames.reduce((accum, timezoneName) => {
|
|
8
5
|
accum[timezoneName] = timezoneName;
|
|
9
6
|
return accum;
|
|
10
7
|
}, {});
|
|
11
8
|
/** The timezone of the current user's environment. */
|
|
12
|
-
|
|
9
|
+
export const userTimezone = Settings.defaultZone.name;
|
|
13
10
|
/** The UTC timezone. */
|
|
14
|
-
|
|
11
|
+
export const utcTimezone = timezones.UTC;
|