date-vir 0.1.1 → 0.2.0
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/dist/cjs/full-date/combine-dates.js +22 -0
- package/dist/cjs/full-date/create-full-date.js +3 -0
- package/dist/cjs/full-date/full-date-shape.js +6 -1
- package/dist/cjs/full-date/primitive-conversions.js +23 -13
- package/dist/cjs/index.js +2 -0
- package/dist/full-date/combine-dates.d.ts +10 -0
- package/dist/full-date/combine-dates.js +22 -0
- package/dist/full-date/create-full-date.js +3 -0
- package/dist/full-date/full-date-shape.d.ts +10 -3
- package/dist/full-date/full-date-shape.js +6 -1
- package/dist/full-date/primitive-conversions.d.ts +17 -20
- package/dist/full-date/primitive-conversions.js +23 -13
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ parseStrangeString({
|
|
|
75
75
|
|
|
76
76
|
```TypeScript
|
|
77
77
|
import {
|
|
78
|
-
|
|
78
|
+
FullDatePartEnum,
|
|
79
79
|
createFullDate,
|
|
80
80
|
formatPresets,
|
|
81
81
|
timezones,
|
|
@@ -111,7 +111,7 @@ toLocaleString(myFullDate, formatPresets.DatetimeFull); // returns 'June 5, 2023
|
|
|
111
111
|
* Formats the given FullDate to a string so that it is ready to be assigned to the value attribute
|
|
112
112
|
* of an <input type="date" /> element.
|
|
113
113
|
*/
|
|
114
|
-
toHtmlInputString(myFullDate,
|
|
114
|
+
toHtmlInputString(myFullDate, FullDatePartEnum.Date); // returns '2023-06-05'
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
# Timezone
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combineDateParts = void 0;
|
|
4
|
+
const full_date_shape_1 = require("./full-date-shape");
|
|
5
|
+
/**
|
|
6
|
+
* Combine two parts of a FullDate objects into a filled-in FullDate. Note that the timezone is
|
|
7
|
+
* taken from the time part. If two complete FullDate objects are passed in, only the respective
|
|
8
|
+
* parts of each is used.
|
|
9
|
+
*/
|
|
10
|
+
function combineDateParts(partialDates) {
|
|
11
|
+
return {
|
|
12
|
+
hour: partialDates[full_date_shape_1.FullDatePartEnum.Time].hour,
|
|
13
|
+
minute: partialDates[full_date_shape_1.FullDatePartEnum.Time].minute,
|
|
14
|
+
second: partialDates[full_date_shape_1.FullDatePartEnum.Time].second,
|
|
15
|
+
millisecond: partialDates[full_date_shape_1.FullDatePartEnum.Time].millisecond,
|
|
16
|
+
timezone: partialDates[full_date_shape_1.FullDatePartEnum.Time].timezone,
|
|
17
|
+
year: partialDates[full_date_shape_1.FullDatePartEnum.Date].year,
|
|
18
|
+
month: partialDates[full_date_shape_1.FullDatePartEnum.Date].month,
|
|
19
|
+
day: partialDates[full_date_shape_1.FullDatePartEnum.Date].day,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.combineDateParts = combineDateParts;
|
|
@@ -35,6 +35,9 @@ exports.createFullDate = createFullDate;
|
|
|
35
35
|
* but represented in a new timezone.
|
|
36
36
|
*/
|
|
37
37
|
function toNewTimezone(fullDate, timezone) {
|
|
38
|
+
if (fullDate.timezone === timezone) {
|
|
39
|
+
return fullDate;
|
|
40
|
+
}
|
|
38
41
|
return createFullDate(fullDate, timezone);
|
|
39
42
|
}
|
|
40
43
|
exports.toNewTimezone = toNewTimezone;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fullDateShape = exports.dateOnlyShape = exports.timeOnlyShape = void 0;
|
|
3
|
+
exports.fullDateShape = exports.dateOnlyShape = exports.timeOnlyShape = exports.FullDatePartEnum = void 0;
|
|
4
4
|
const object_shape_tester_1 = require("object-shape-tester");
|
|
5
5
|
const timezones_1 = require("../timezone/timezones");
|
|
6
|
+
var FullDatePartEnum;
|
|
7
|
+
(function (FullDatePartEnum) {
|
|
8
|
+
FullDatePartEnum["Date"] = "date";
|
|
9
|
+
FullDatePartEnum["Time"] = "time";
|
|
10
|
+
})(FullDatePartEnum = exports.FullDatePartEnum || (exports.FullDatePartEnum = {}));
|
|
6
11
|
exports.timeOnlyShape = (0, object_shape_tester_1.defineShape)({
|
|
7
12
|
/** Hour of the day in 24 time: 0-23 */
|
|
8
13
|
hour: 14,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toHtmlInputString = exports.
|
|
3
|
+
exports.toHtmlInputString = exports.toFormattedString = exports.toLocaleString = exports.toIsoString = exports.toTimestamp = void 0;
|
|
4
4
|
const common_1 = require("@augment-vir/common");
|
|
5
5
|
const locales_1 = require("../locales");
|
|
6
6
|
const timezones_1 = require("../timezone/timezones");
|
|
7
|
+
const full_date_shape_1 = require("./full-date-shape");
|
|
7
8
|
const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
|
|
8
9
|
/** Convert a FullDate into a unix timestamp with milliseconds. */
|
|
9
10
|
function toTimestamp(fullDate) {
|
|
@@ -41,17 +42,17 @@ function toFormattedString(fullDate, format, localeOverride = locales_1.userLoca
|
|
|
41
42
|
return (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).toFormat(format, { locale: localeOverride });
|
|
42
43
|
}
|
|
43
44
|
exports.toFormattedString = toFormattedString;
|
|
44
|
-
/**
|
|
45
|
-
* The different options for the "type" attribute in an <input> element that require specific
|
|
46
|
-
* formatting relevant to dates.
|
|
47
|
-
*/
|
|
48
|
-
var HtmlInputElementTypeEnum;
|
|
49
|
-
(function (HtmlInputElementTypeEnum) {
|
|
50
|
-
HtmlInputElementTypeEnum["Date"] = "date";
|
|
51
|
-
HtmlInputElementTypeEnum["Time"] = "time";
|
|
52
|
-
})(HtmlInputElementTypeEnum = exports.HtmlInputElementTypeEnum || (exports.HtmlInputElementTypeEnum = {}));
|
|
53
45
|
function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
54
|
-
if (inputType ===
|
|
46
|
+
if (inputType === full_date_shape_1.FullDatePartEnum.Date) {
|
|
47
|
+
if (fullDate.year == undefined) {
|
|
48
|
+
throw new Error(`Tried to create date string but no year was provided.`);
|
|
49
|
+
}
|
|
50
|
+
if (fullDate.month == undefined) {
|
|
51
|
+
throw new Error(`Tried to create date string but no month was provided.`);
|
|
52
|
+
}
|
|
53
|
+
if (fullDate.day == undefined) {
|
|
54
|
+
throw new Error(`Tried to create date string but no day was provided.`);
|
|
55
|
+
}
|
|
55
56
|
const dateParts = [
|
|
56
57
|
fullDate.year,
|
|
57
58
|
String(fullDate.month).padStart(2, '0'),
|
|
@@ -59,7 +60,16 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
|
59
60
|
];
|
|
60
61
|
return dateParts.join('-');
|
|
61
62
|
}
|
|
62
|
-
else if (inputType ===
|
|
63
|
+
else if (inputType === full_date_shape_1.FullDatePartEnum.Time) {
|
|
64
|
+
if (includeSeconds && fullDate.second == undefined) {
|
|
65
|
+
throw new Error('Tried to include seconds in the time string but no seconds were provided.');
|
|
66
|
+
}
|
|
67
|
+
if (fullDate.hour == undefined) {
|
|
68
|
+
throw new Error(`Tried to create time string but no hour was provided.`);
|
|
69
|
+
}
|
|
70
|
+
if (fullDate.minute == undefined) {
|
|
71
|
+
throw new Error(`Tried to create time string but no minutes were provided.`);
|
|
72
|
+
}
|
|
63
73
|
const timeParts = [
|
|
64
74
|
String(fullDate.hour).padStart(2, '0'),
|
|
65
75
|
String(fullDate.minute).padStart(2, '0'),
|
|
@@ -68,7 +78,7 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
|
68
78
|
return timeParts.join(':');
|
|
69
79
|
}
|
|
70
80
|
else {
|
|
71
|
-
throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of
|
|
81
|
+
throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of FullDatePartEnum or one of ${(0, common_1.getEnumTypedValues)(full_date_shape_1.FullDatePartEnum).join(', ')}.`);
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
84
|
exports.toHtmlInputString = toHtmlInputString;
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./full-date/calculate-relative-date"), exports);
|
|
18
|
+
__exportStar(require("./full-date/combine-dates"), exports);
|
|
17
19
|
__exportStar(require("./full-date/create-full-date"), exports);
|
|
18
20
|
__exportStar(require("./full-date/date-like"), exports);
|
|
19
21
|
__exportStar(require("./full-date/format-presets"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DatePart, FullDate, FullDatePartEnum, TimePart } from './full-date-shape';
|
|
2
|
+
/**
|
|
3
|
+
* Combine two parts of a FullDate objects into a filled-in FullDate. Note that the timezone is
|
|
4
|
+
* taken from the time part. If two complete FullDate objects are passed in, only the respective
|
|
5
|
+
* parts of each is used.
|
|
6
|
+
*/
|
|
7
|
+
export declare function combineDateParts(partialDates: {
|
|
8
|
+
[FullDatePartEnum.Date]: DatePart;
|
|
9
|
+
[FullDatePartEnum.Time]: TimePart;
|
|
10
|
+
}): FullDate;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combineDateParts = void 0;
|
|
4
|
+
const full_date_shape_1 = require("./full-date-shape");
|
|
5
|
+
/**
|
|
6
|
+
* Combine two parts of a FullDate objects into a filled-in FullDate. Note that the timezone is
|
|
7
|
+
* taken from the time part. If two complete FullDate objects are passed in, only the respective
|
|
8
|
+
* parts of each is used.
|
|
9
|
+
*/
|
|
10
|
+
function combineDateParts(partialDates) {
|
|
11
|
+
return {
|
|
12
|
+
hour: partialDates[full_date_shape_1.FullDatePartEnum.Time].hour,
|
|
13
|
+
minute: partialDates[full_date_shape_1.FullDatePartEnum.Time].minute,
|
|
14
|
+
second: partialDates[full_date_shape_1.FullDatePartEnum.Time].second,
|
|
15
|
+
millisecond: partialDates[full_date_shape_1.FullDatePartEnum.Time].millisecond,
|
|
16
|
+
timezone: partialDates[full_date_shape_1.FullDatePartEnum.Time].timezone,
|
|
17
|
+
year: partialDates[full_date_shape_1.FullDatePartEnum.Date].year,
|
|
18
|
+
month: partialDates[full_date_shape_1.FullDatePartEnum.Date].month,
|
|
19
|
+
day: partialDates[full_date_shape_1.FullDatePartEnum.Date].day,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.combineDateParts = combineDateParts;
|
|
@@ -35,6 +35,9 @@ exports.createFullDate = createFullDate;
|
|
|
35
35
|
* but represented in a new timezone.
|
|
36
36
|
*/
|
|
37
37
|
function toNewTimezone(fullDate, timezone) {
|
|
38
|
+
if (fullDate.timezone === timezone) {
|
|
39
|
+
return fullDate;
|
|
40
|
+
}
|
|
38
41
|
return createFullDate(fullDate, timezone);
|
|
39
42
|
}
|
|
40
43
|
exports.toNewTimezone = toNewTimezone;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { Overwrite } from '@augment-vir/common';
|
|
1
|
+
import { Overwrite, RequiredBy } from '@augment-vir/common';
|
|
2
2
|
import { Timezone } from '../timezone/timezone-names';
|
|
3
|
+
export declare enum FullDatePartEnum {
|
|
4
|
+
Date = "date",
|
|
5
|
+
Time = "time"
|
|
6
|
+
}
|
|
3
7
|
export type WithTimezone = {
|
|
4
8
|
timezone: Timezone;
|
|
5
9
|
};
|
|
@@ -15,7 +19,8 @@ export declare const timeOnlyShape: import("object-shape-tester").ShapeDefinitio
|
|
|
15
19
|
/** The timezone that this date/time is meant for / originated from. */
|
|
16
20
|
timezone: "UTC";
|
|
17
21
|
}>;
|
|
18
|
-
|
|
22
|
+
type TimeOnlyPart = Overwrite<(typeof timeOnlyShape)['runTimeType'], WithTimezone>;
|
|
23
|
+
export type TimePart = RequiredBy<Partial<FullDate>, keyof TimeOnlyPart>;
|
|
19
24
|
export declare const dateOnlyShape: import("object-shape-tester").ShapeDefinition<{
|
|
20
25
|
/**
|
|
21
26
|
* The full, four digit year.
|
|
@@ -31,7 +36,8 @@ export declare const dateOnlyShape: import("object-shape-tester").ShapeDefinitio
|
|
|
31
36
|
/** The timezone that this date/time is meant for / originated from. */
|
|
32
37
|
timezone: "UTC";
|
|
33
38
|
}>;
|
|
34
|
-
|
|
39
|
+
type DateOnlyPart = Overwrite<(typeof dateOnlyShape)['runTimeType'], WithTimezone>;
|
|
40
|
+
export type DatePart = RequiredBy<Partial<FullDate>, keyof DateOnlyPart>;
|
|
35
41
|
export declare const fullDateShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
|
|
36
42
|
/**
|
|
37
43
|
* The full, four digit year.
|
|
@@ -63,3 +69,4 @@ export declare const fullDateShape: import("object-shape-tester").ShapeDefinitio
|
|
|
63
69
|
* be represented with minimal data.
|
|
64
70
|
*/
|
|
65
71
|
export type FullDate = Overwrite<(typeof fullDateShape)['runTimeType'], WithTimezone>;
|
|
72
|
+
export {};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fullDateShape = exports.dateOnlyShape = exports.timeOnlyShape = void 0;
|
|
3
|
+
exports.fullDateShape = exports.dateOnlyShape = exports.timeOnlyShape = exports.FullDatePartEnum = void 0;
|
|
4
4
|
const object_shape_tester_1 = require("object-shape-tester");
|
|
5
5
|
const timezones_1 = require("../timezone/timezones");
|
|
6
|
+
var FullDatePartEnum;
|
|
7
|
+
(function (FullDatePartEnum) {
|
|
8
|
+
FullDatePartEnum["Date"] = "date";
|
|
9
|
+
FullDatePartEnum["Time"] = "time";
|
|
10
|
+
})(FullDatePartEnum = exports.FullDatePartEnum || (exports.FullDatePartEnum = {}));
|
|
6
11
|
exports.timeOnlyShape = (0, object_shape_tester_1.defineShape)({
|
|
7
12
|
/** Hour of the day in 24 time: 0-23 */
|
|
8
13
|
hour: 14,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PartialAndUndefined } from '@augment-vir/common';
|
|
2
|
-
import {
|
|
1
|
+
import { PartialAndUndefined, RequiredBy } from '@augment-vir/common';
|
|
2
|
+
import { SetOptional } from 'type-fest';
|
|
3
|
+
import { DatePart, FullDate, FullDatePartEnum } from './full-date-shape';
|
|
3
4
|
import { JustDateString, JustTimeString, JustTimeWithSecondsString, UtcIsoString } from './string-format-types';
|
|
4
5
|
/** Convert a FullDate into a unix timestamp with milliseconds. */
|
|
5
6
|
export declare function toTimestamp(fullDate: FullDate): number;
|
|
@@ -17,26 +18,22 @@ export declare function toLocaleString(fullDate: FullDate, formatOptions?: (Intl
|
|
|
17
18
|
* already has many formatting options.
|
|
18
19
|
*/
|
|
19
20
|
export declare function toFormattedString(fullDate: FullDate, format: string, localeOverride?: string): string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/
|
|
24
|
-
export declare enum HtmlInputElementTypeEnum {
|
|
25
|
-
Date = "date",
|
|
26
|
-
Time = "time"
|
|
27
|
-
}
|
|
21
|
+
type OnlyDatePart = SetOptional<DatePart, 'timezone'>;
|
|
22
|
+
type HourMinutePart = RequiredBy<Partial<FullDate>, 'hour' | 'minute'>;
|
|
23
|
+
type HourMinuteSecondPart = RequiredBy<Partial<FullDate>, 'hour' | 'minute' | 'second'>;
|
|
28
24
|
/**
|
|
29
25
|
* Converts a FullDate object into a string that is understood by type="date" or type="time"
|
|
30
26
|
* HTMLInputElement instances. Can optionally include seconds as well for type="time".
|
|
31
27
|
*
|
|
32
|
-
* This
|
|
33
|
-
* string. If you wish to convert time zones, first call
|
|
34
|
-
*
|
|
28
|
+
* This function ignores the timezone, the literal stored date and time numbers are simply
|
|
29
|
+
* concatenated into a string. If you wish to convert time zones, first call toNewTimezone on your
|
|
30
|
+
* FullDate object.
|
|
35
31
|
*/
|
|
36
|
-
export declare function toHtmlInputString(fullDate:
|
|
37
|
-
export declare function toHtmlInputString(fullDate:
|
|
38
|
-
export declare function toHtmlInputString(fullDate:
|
|
39
|
-
export declare function toHtmlInputString(fullDate:
|
|
40
|
-
export declare function toHtmlInputString(fullDate:
|
|
41
|
-
export declare function toHtmlInputString(fullDate:
|
|
42
|
-
export declare function toHtmlInputString(fullDate:
|
|
32
|
+
export declare function toHtmlInputString(fullDate: OnlyDatePart, inputType: FullDatePartEnum.Date): JustDateString;
|
|
33
|
+
export declare function toHtmlInputString(fullDate: HourMinutePart, inputType: FullDatePartEnum.Time, includeSeconds?: false | undefined): JustTimeString;
|
|
34
|
+
export declare function toHtmlInputString(fullDate: HourMinuteSecondPart, inputType: FullDatePartEnum.Time, includeSeconds: true): JustTimeWithSecondsString;
|
|
35
|
+
export declare function toHtmlInputString(fullDate: HourMinutePart | HourMinuteSecondPart, inputType: FullDatePartEnum.Time, includeSeconds?: boolean | undefined): JustTimeWithSecondsString | JustTimeString;
|
|
36
|
+
export declare function toHtmlInputString(fullDate: HourMinuteSecondPart | OnlyDatePart, inputType: FullDatePartEnum, includeSeconds: true): JustDateString | JustTimeWithSecondsString;
|
|
37
|
+
export declare function toHtmlInputString(fullDate: HourMinutePart | OnlyDatePart, inputType: FullDatePartEnum, includeSeconds?: false | undefined): JustDateString | JustTimeString;
|
|
38
|
+
export declare function toHtmlInputString(fullDate: HourMinutePart | HourMinuteSecondPart | OnlyDatePart, inputType: FullDatePartEnum, includeSeconds?: boolean | undefined): JustDateString | JustTimeWithSecondsString | JustTimeString;
|
|
39
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toHtmlInputString = exports.
|
|
3
|
+
exports.toHtmlInputString = exports.toFormattedString = exports.toLocaleString = exports.toIsoString = exports.toTimestamp = void 0;
|
|
4
4
|
const common_1 = require("@augment-vir/common");
|
|
5
5
|
const locales_1 = require("../locales");
|
|
6
6
|
const timezones_1 = require("../timezone/timezones");
|
|
7
|
+
const full_date_shape_1 = require("./full-date-shape");
|
|
7
8
|
const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
|
|
8
9
|
/** Convert a FullDate into a unix timestamp with milliseconds. */
|
|
9
10
|
function toTimestamp(fullDate) {
|
|
@@ -41,17 +42,17 @@ function toFormattedString(fullDate, format, localeOverride = locales_1.userLoca
|
|
|
41
42
|
return (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).toFormat(format, { locale: localeOverride });
|
|
42
43
|
}
|
|
43
44
|
exports.toFormattedString = toFormattedString;
|
|
44
|
-
/**
|
|
45
|
-
* The different options for the "type" attribute in an <input> element that require specific
|
|
46
|
-
* formatting relevant to dates.
|
|
47
|
-
*/
|
|
48
|
-
var HtmlInputElementTypeEnum;
|
|
49
|
-
(function (HtmlInputElementTypeEnum) {
|
|
50
|
-
HtmlInputElementTypeEnum["Date"] = "date";
|
|
51
|
-
HtmlInputElementTypeEnum["Time"] = "time";
|
|
52
|
-
})(HtmlInputElementTypeEnum = exports.HtmlInputElementTypeEnum || (exports.HtmlInputElementTypeEnum = {}));
|
|
53
45
|
function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
54
|
-
if (inputType ===
|
|
46
|
+
if (inputType === full_date_shape_1.FullDatePartEnum.Date) {
|
|
47
|
+
if (fullDate.year == undefined) {
|
|
48
|
+
throw new Error(`Tried to create date string but no year was provided.`);
|
|
49
|
+
}
|
|
50
|
+
if (fullDate.month == undefined) {
|
|
51
|
+
throw new Error(`Tried to create date string but no month was provided.`);
|
|
52
|
+
}
|
|
53
|
+
if (fullDate.day == undefined) {
|
|
54
|
+
throw new Error(`Tried to create date string but no day was provided.`);
|
|
55
|
+
}
|
|
55
56
|
const dateParts = [
|
|
56
57
|
fullDate.year,
|
|
57
58
|
String(fullDate.month).padStart(2, '0'),
|
|
@@ -59,7 +60,16 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
|
59
60
|
];
|
|
60
61
|
return dateParts.join('-');
|
|
61
62
|
}
|
|
62
|
-
else if (inputType ===
|
|
63
|
+
else if (inputType === full_date_shape_1.FullDatePartEnum.Time) {
|
|
64
|
+
if (includeSeconds && fullDate.second == undefined) {
|
|
65
|
+
throw new Error('Tried to include seconds in the time string but no seconds were provided.');
|
|
66
|
+
}
|
|
67
|
+
if (fullDate.hour == undefined) {
|
|
68
|
+
throw new Error(`Tried to create time string but no hour was provided.`);
|
|
69
|
+
}
|
|
70
|
+
if (fullDate.minute == undefined) {
|
|
71
|
+
throw new Error(`Tried to create time string but no minutes were provided.`);
|
|
72
|
+
}
|
|
63
73
|
const timeParts = [
|
|
64
74
|
String(fullDate.hour).padStart(2, '0'),
|
|
65
75
|
String(fullDate.minute).padStart(2, '0'),
|
|
@@ -68,7 +78,7 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
|
68
78
|
return timeParts.join(':');
|
|
69
79
|
}
|
|
70
80
|
else {
|
|
71
|
-
throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of
|
|
81
|
+
throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of FullDatePartEnum or one of ${(0, common_1.getEnumTypedValues)(full_date_shape_1.FullDatePartEnum).join(', ')}.`);
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
84
|
exports.toHtmlInputString = toHtmlInputString;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./full-date/calculate-relative-date"), exports);
|
|
18
|
+
__exportStar(require("./full-date/combine-dates"), exports);
|
|
17
19
|
__exportStar(require("./full-date/create-full-date"), exports);
|
|
18
20
|
__exportStar(require("./full-date/date-like"), exports);
|
|
19
21
|
__exportStar(require("./full-date/format-presets"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-vir",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Easy and explicit dates and times",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"@augment-vir/common": "^14.2.2",
|
|
43
43
|
"@types/luxon": "^3.3.0",
|
|
44
44
|
"luxon": "^3.3.0",
|
|
45
|
-
"object-shape-tester": "^0.2.7"
|
|
45
|
+
"object-shape-tester": "^0.2.7",
|
|
46
|
+
"type-fest": "^3.11.1"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@augment-vir/browser-testing": "^14.2.2",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"@web/test-runner-playwright": "^0.10.0",
|
|
56
57
|
"@web/test-runner-visual-regression": "^0.8.0",
|
|
57
58
|
"cspell": "^6.31.1",
|
|
58
|
-
"element-vir": "^13.0.
|
|
59
|
+
"element-vir": "^13.0.3",
|
|
59
60
|
"esbuild": "^0.17.19",
|
|
60
61
|
"istanbul-smart-text-reporter": "^1.1.2",
|
|
61
62
|
"markdown-code-example-inserter": "^0.3.1",
|