date-vir 0.2.0 → 0.2.1
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/combine-dates.js +34 -16
- package/dist/cjs/full-date/full-date-shape.js +4 -4
- package/dist/full-date/combine-dates.d.ts +31 -4
- package/dist/full-date/combine-dates.js +34 -16
- package/dist/full-date/full-date-shape.d.ts +7 -11
- package/dist/full-date/full-date-shape.js +4 -4
- package/package.json +1 -1
|
@@ -2,21 +2,39 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.combineDateParts = void 0;
|
|
4
4
|
const full_date_shape_1 = require("./full-date-shape");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
function combineDateParts(maybeDateParts) {
|
|
6
|
+
const timePart = maybeDateParts.time
|
|
7
|
+
? {
|
|
8
|
+
hour: maybeDateParts.time.hour,
|
|
9
|
+
minute: maybeDateParts.time.minute,
|
|
10
|
+
second: maybeDateParts.time.second,
|
|
11
|
+
millisecond: maybeDateParts.time.millisecond,
|
|
12
|
+
timezone: maybeDateParts.time.timezone,
|
|
13
|
+
}
|
|
14
|
+
: undefined;
|
|
15
|
+
const datePart = maybeDateParts.date
|
|
16
|
+
? {
|
|
17
|
+
year: maybeDateParts.date.year,
|
|
18
|
+
month: maybeDateParts.date.month,
|
|
19
|
+
day: maybeDateParts.date.day,
|
|
20
|
+
timezone: maybeDateParts.date.timezone,
|
|
21
|
+
}
|
|
22
|
+
: undefined;
|
|
23
|
+
if (timePart && datePart) {
|
|
24
|
+
if (timePart.timezone !== datePart.timezone) {
|
|
25
|
+
throw new Error(`Time and date parts have mismatching timezones. Got '${timePart.timezone}' and '${datePart.timezone}'.`);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...timePart,
|
|
29
|
+
...datePart,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (timePart) {
|
|
33
|
+
return timePart;
|
|
34
|
+
}
|
|
35
|
+
if (datePart) {
|
|
36
|
+
return datePart;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
21
39
|
}
|
|
22
40
|
exports.combineDateParts = combineDateParts;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fullDateShape = exports.
|
|
3
|
+
exports.fullDateShape = exports.datePartShape = exports.timePartShape = exports.FullDatePartEnum = void 0;
|
|
4
4
|
const object_shape_tester_1 = require("object-shape-tester");
|
|
5
5
|
const timezones_1 = require("../timezone/timezones");
|
|
6
6
|
var FullDatePartEnum;
|
|
@@ -8,7 +8,7 @@ var FullDatePartEnum;
|
|
|
8
8
|
FullDatePartEnum["Date"] = "date";
|
|
9
9
|
FullDatePartEnum["Time"] = "time";
|
|
10
10
|
})(FullDatePartEnum = exports.FullDatePartEnum || (exports.FullDatePartEnum = {}));
|
|
11
|
-
exports.
|
|
11
|
+
exports.timePartShape = (0, object_shape_tester_1.defineShape)({
|
|
12
12
|
/** Hour of the day in 24 time: 0-23 */
|
|
13
13
|
hour: 14,
|
|
14
14
|
/** Minute of the hour: 0-59 */
|
|
@@ -20,7 +20,7 @@ exports.timeOnlyShape = (0, object_shape_tester_1.defineShape)({
|
|
|
20
20
|
/** The timezone that this date/time is meant for / originated from. */
|
|
21
21
|
timezone: timezones_1.utcTimezone,
|
|
22
22
|
});
|
|
23
|
-
exports.
|
|
23
|
+
exports.datePartShape = (0, object_shape_tester_1.defineShape)({
|
|
24
24
|
/**
|
|
25
25
|
* The full, four digit year.
|
|
26
26
|
*
|
|
@@ -35,4 +35,4 @@ exports.dateOnlyShape = (0, object_shape_tester_1.defineShape)({
|
|
|
35
35
|
/** The timezone that this date/time is meant for / originated from. */
|
|
36
36
|
timezone: timezones_1.utcTimezone,
|
|
37
37
|
});
|
|
38
|
-
exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.
|
|
38
|
+
exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.datePartShape, exports.timePartShape));
|
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
import { DatePart, FullDate, FullDatePartEnum, TimePart } from './full-date-shape';
|
|
2
|
+
type MaybeDateParts = Partial<{
|
|
3
|
+
[FullDatePartEnum.Date]: DatePart | undefined;
|
|
4
|
+
[FullDatePartEnum.Time]: TimePart | undefined;
|
|
5
|
+
}>;
|
|
6
|
+
export type MaybeDatePart = FullDate | DatePart | TimePart | undefined;
|
|
2
7
|
/**
|
|
3
|
-
* Combine two parts of a FullDate objects into a filled-in FullDate. Note that the
|
|
4
|
-
*
|
|
5
|
-
*
|
|
8
|
+
* Combine two parts of a FullDate objects into a filled-in FullDate. Note that the timezones must
|
|
9
|
+
* match for both inputs. If two complete FullDate objects are passed in, only the respective parts
|
|
10
|
+
* of each is used.
|
|
6
11
|
*/
|
|
7
|
-
export declare function combineDateParts(
|
|
12
|
+
export declare function combineDateParts(maybeDateParts: {
|
|
8
13
|
[FullDatePartEnum.Date]: DatePart;
|
|
9
14
|
[FullDatePartEnum.Time]: TimePart;
|
|
10
15
|
}): FullDate;
|
|
16
|
+
export declare function combineDateParts(maybeDateParts: {
|
|
17
|
+
[FullDatePartEnum.Date]?: undefined;
|
|
18
|
+
[FullDatePartEnum.Time]?: undefined;
|
|
19
|
+
}): undefined;
|
|
20
|
+
export declare function combineDateParts(maybeDateParts: {
|
|
21
|
+
[FullDatePartEnum.Date]: DatePart;
|
|
22
|
+
[FullDatePartEnum.Time]?: undefined;
|
|
23
|
+
}): DatePart;
|
|
24
|
+
export declare function combineDateParts(maybeDateParts: {
|
|
25
|
+
[FullDatePartEnum.Date]: DatePart;
|
|
26
|
+
[FullDatePartEnum.Time]?: TimePart | undefined;
|
|
27
|
+
}): FullDate | DatePart;
|
|
28
|
+
export declare function combineDateParts(maybeDateParts: {
|
|
29
|
+
[FullDatePartEnum.Date]?: undefined;
|
|
30
|
+
[FullDatePartEnum.Time]: TimePart;
|
|
31
|
+
}): TimePart;
|
|
32
|
+
export declare function combineDateParts(maybeDateParts: {
|
|
33
|
+
[FullDatePartEnum.Date]?: DatePart | undefined;
|
|
34
|
+
[FullDatePartEnum.Time]: TimePart;
|
|
35
|
+
}): FullDate | TimePart;
|
|
36
|
+
export declare function combineDateParts(maybeDateParts: MaybeDateParts): MaybeDatePart;
|
|
37
|
+
export {};
|
|
@@ -2,21 +2,39 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.combineDateParts = void 0;
|
|
4
4
|
const full_date_shape_1 = require("./full-date-shape");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
function combineDateParts(maybeDateParts) {
|
|
6
|
+
const timePart = maybeDateParts.time
|
|
7
|
+
? {
|
|
8
|
+
hour: maybeDateParts.time.hour,
|
|
9
|
+
minute: maybeDateParts.time.minute,
|
|
10
|
+
second: maybeDateParts.time.second,
|
|
11
|
+
millisecond: maybeDateParts.time.millisecond,
|
|
12
|
+
timezone: maybeDateParts.time.timezone,
|
|
13
|
+
}
|
|
14
|
+
: undefined;
|
|
15
|
+
const datePart = maybeDateParts.date
|
|
16
|
+
? {
|
|
17
|
+
year: maybeDateParts.date.year,
|
|
18
|
+
month: maybeDateParts.date.month,
|
|
19
|
+
day: maybeDateParts.date.day,
|
|
20
|
+
timezone: maybeDateParts.date.timezone,
|
|
21
|
+
}
|
|
22
|
+
: undefined;
|
|
23
|
+
if (timePart && datePart) {
|
|
24
|
+
if (timePart.timezone !== datePart.timezone) {
|
|
25
|
+
throw new Error(`Time and date parts have mismatching timezones. Got '${timePart.timezone}' and '${datePart.timezone}'.`);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...timePart,
|
|
29
|
+
...datePart,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (timePart) {
|
|
33
|
+
return timePart;
|
|
34
|
+
}
|
|
35
|
+
if (datePart) {
|
|
36
|
+
return datePart;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
21
39
|
}
|
|
22
40
|
exports.combineDateParts = combineDateParts;
|
|
@@ -4,10 +4,7 @@ export declare enum FullDatePartEnum {
|
|
|
4
4
|
Date = "date",
|
|
5
5
|
Time = "time"
|
|
6
6
|
}
|
|
7
|
-
export
|
|
8
|
-
timezone: Timezone;
|
|
9
|
-
};
|
|
10
|
-
export declare const timeOnlyShape: import("object-shape-tester").ShapeDefinition<{
|
|
7
|
+
export declare const timePartShape: import("object-shape-tester").ShapeDefinition<{
|
|
11
8
|
/** Hour of the day in 24 time: 0-23 */
|
|
12
9
|
hour: number;
|
|
13
10
|
/** Minute of the hour: 0-59 */
|
|
@@ -19,9 +16,8 @@ export declare const timeOnlyShape: import("object-shape-tester").ShapeDefinitio
|
|
|
19
16
|
/** The timezone that this date/time is meant for / originated from. */
|
|
20
17
|
timezone: "UTC";
|
|
21
18
|
}>;
|
|
22
|
-
type
|
|
23
|
-
export
|
|
24
|
-
export declare const dateOnlyShape: import("object-shape-tester").ShapeDefinition<{
|
|
19
|
+
export type TimePart = RequiredBy<Partial<FullDate>, keyof (typeof timePartShape)['runTimeType']>;
|
|
20
|
+
export declare const datePartShape: import("object-shape-tester").ShapeDefinition<{
|
|
25
21
|
/**
|
|
26
22
|
* The full, four digit year.
|
|
27
23
|
*
|
|
@@ -36,8 +32,7 @@ export declare const dateOnlyShape: import("object-shape-tester").ShapeDefinitio
|
|
|
36
32
|
/** The timezone that this date/time is meant for / originated from. */
|
|
37
33
|
timezone: "UTC";
|
|
38
34
|
}>;
|
|
39
|
-
type
|
|
40
|
-
export type DatePart = RequiredBy<Partial<FullDate>, keyof DateOnlyPart>;
|
|
35
|
+
export type DatePart = RequiredBy<Partial<FullDate>, keyof (typeof datePartShape)['runTimeType']>;
|
|
41
36
|
export declare const fullDateShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
|
|
42
37
|
/**
|
|
43
38
|
* The full, four digit year.
|
|
@@ -68,5 +63,6 @@ export declare const fullDateShape: import("object-shape-tester").ShapeDefinitio
|
|
|
68
63
|
* A easily serializable (it fits into plain JSON) object that completely defines how a date is to
|
|
69
64
|
* be represented with minimal data.
|
|
70
65
|
*/
|
|
71
|
-
export type FullDate = Overwrite<(typeof fullDateShape)['runTimeType'],
|
|
72
|
-
|
|
66
|
+
export type FullDate = Overwrite<(typeof fullDateShape)['runTimeType'], {
|
|
67
|
+
timezone: Timezone;
|
|
68
|
+
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fullDateShape = exports.
|
|
3
|
+
exports.fullDateShape = exports.datePartShape = exports.timePartShape = exports.FullDatePartEnum = void 0;
|
|
4
4
|
const object_shape_tester_1 = require("object-shape-tester");
|
|
5
5
|
const timezones_1 = require("../timezone/timezones");
|
|
6
6
|
var FullDatePartEnum;
|
|
@@ -8,7 +8,7 @@ var FullDatePartEnum;
|
|
|
8
8
|
FullDatePartEnum["Date"] = "date";
|
|
9
9
|
FullDatePartEnum["Time"] = "time";
|
|
10
10
|
})(FullDatePartEnum = exports.FullDatePartEnum || (exports.FullDatePartEnum = {}));
|
|
11
|
-
exports.
|
|
11
|
+
exports.timePartShape = (0, object_shape_tester_1.defineShape)({
|
|
12
12
|
/** Hour of the day in 24 time: 0-23 */
|
|
13
13
|
hour: 14,
|
|
14
14
|
/** Minute of the hour: 0-59 */
|
|
@@ -20,7 +20,7 @@ exports.timeOnlyShape = (0, object_shape_tester_1.defineShape)({
|
|
|
20
20
|
/** The timezone that this date/time is meant for / originated from. */
|
|
21
21
|
timezone: timezones_1.utcTimezone,
|
|
22
22
|
});
|
|
23
|
-
exports.
|
|
23
|
+
exports.datePartShape = (0, object_shape_tester_1.defineShape)({
|
|
24
24
|
/**
|
|
25
25
|
* The full, four digit year.
|
|
26
26
|
*
|
|
@@ -35,4 +35,4 @@ exports.dateOnlyShape = (0, object_shape_tester_1.defineShape)({
|
|
|
35
35
|
/** The timezone that this date/time is meant for / originated from. */
|
|
36
36
|
timezone: timezones_1.utcTimezone,
|
|
37
37
|
});
|
|
38
|
-
exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.
|
|
38
|
+
exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.datePartShape, exports.timePartShape));
|