@finnair/v-validation-luxon 1.1.0-alpha.4 → 1.1.0-alpha.7
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 +42 -0
- package/dist/Vluxon.d.ts +4 -4
- package/dist/Vluxon.js +22 -29
- package/dist/luxon.d.ts +36 -38
- package/dist/luxon.js +66 -75
- package/dist/test-luxon.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,48 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.1.0-alpha.7](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.6...v1.1.0-alpha.7) (2022-08-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @finnair/v-validation-luxon
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [1.1.0-alpha.6](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.6) (2022-08-17)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* Fix exports ([b9eacb6](https://github.com/finnair/v-validation/commit/b9eacb6e98a05a07049eb0a8f97b7e6b4958973a))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* fromISO helper for Luxon wrapper construction ([e3b8f24](https://github.com/finnair/v-validation/commit/e3b8f247b3a9bfef8ad474688f995862fdd810e3))
|
|
25
|
+
* Support for Luxon ([00d0a8e](https://github.com/finnair/v-validation/commit/00d0a8e8c8de46bfeb3502f51bb8cd5a3627070e))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# [1.1.0-alpha.5](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.5) (2022-08-16)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
* Fix exports ([904e63c](https://github.com/finnair/v-validation/commit/904e63c4a40e65d274349ae0f5ea80c697c5c8ce))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
* fromISO helper for Luxon wrapper construction ([81d5b2e](https://github.com/finnair/v-validation/commit/81d5b2eb08f360ab56ec0c6caece392a0e6eb1a1))
|
|
42
|
+
* Support for Luxon ([6a243f0](https://github.com/finnair/v-validation/commit/6a243f043db2ca6700180eb758a08d8edfe1e538))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
6
48
|
# [1.1.0-alpha.4](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.3...v1.1.0-alpha.4) (2022-08-15)
|
|
7
49
|
|
|
8
50
|
**Note:** Version bump only for package @finnair/v-validation-luxon
|
package/dist/Vluxon.d.ts
CHANGED
|
@@ -10,18 +10,18 @@ export interface ValidateLuxonParams {
|
|
|
10
10
|
type: string;
|
|
11
11
|
proto: any;
|
|
12
12
|
pattern: RegExp;
|
|
13
|
+
parser: (value: string) => DateTime;
|
|
13
14
|
}
|
|
14
|
-
export declare function validateLuxon({ value, path, ctx, type, proto, pattern }: ValidateLuxonParams): ValidationResult;
|
|
15
|
+
export declare function validateLuxon({ value, path, ctx, type, proto, pattern, parser }: ValidateLuxonParams): ValidationResult;
|
|
15
16
|
export declare class DurationValidator extends Validator {
|
|
16
17
|
validatePath(value: any, path: Path, ctx: ValidationContext): Promise<ValidationResult>;
|
|
17
18
|
}
|
|
18
19
|
export declare const Vluxon: {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
localDate: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
21
|
+
localTime: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
21
22
|
dateTime: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
22
23
|
dateTimeUtc: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
23
24
|
dateTimeMillis: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
24
25
|
dateTimeMillisUtc: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
25
|
-
time: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
26
26
|
duration: () => DurationValidator;
|
|
27
27
|
};
|
package/dist/Vluxon.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.Vluxon = exports.DurationValidator = exports.validateLuxon = void 0;
|
|
|
13
13
|
const v_validation_1 = require("@finnair/v-validation");
|
|
14
14
|
const luxon_1 = require("luxon");
|
|
15
15
|
const luxon_2 = require("./luxon");
|
|
16
|
-
function validateLuxon({ value, path, ctx, type, proto, pattern }) {
|
|
16
|
+
function validateLuxon({ value, path, ctx, type, proto, pattern, parser }) {
|
|
17
17
|
if ((0, v_validation_1.isNullOrUndefined)(value)) {
|
|
18
18
|
return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
|
|
19
19
|
}
|
|
@@ -27,7 +27,7 @@ function validateLuxon({ value, path, ctx, type, proto, pattern }) {
|
|
|
27
27
|
}
|
|
28
28
|
else if ((0, v_validation_1.isString)(value)) {
|
|
29
29
|
if (pattern.test(value)) {
|
|
30
|
-
const dateTime =
|
|
30
|
+
const dateTime = parser(value);
|
|
31
31
|
if (dateTime.isValid) {
|
|
32
32
|
return ctx.success(new proto(dateTime));
|
|
33
33
|
}
|
|
@@ -37,27 +37,30 @@ function validateLuxon({ value, path, ctx, type, proto, pattern }) {
|
|
|
37
37
|
}
|
|
38
38
|
exports.validateLuxon = validateLuxon;
|
|
39
39
|
const datePattern = /^\d{4}-\d{2}-\d{2}$/;
|
|
40
|
-
function
|
|
40
|
+
function localDateValidator(value, path, ctx) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
42
|
return validateLuxon({
|
|
43
43
|
value,
|
|
44
44
|
path,
|
|
45
45
|
ctx,
|
|
46
46
|
type: 'Date',
|
|
47
|
-
proto: luxon_2.
|
|
48
|
-
pattern: datePattern
|
|
47
|
+
proto: luxon_2.LocalDateLuxon,
|
|
48
|
+
pattern: datePattern,
|
|
49
|
+
parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
|
|
49
50
|
});
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
const timePattern = /^\d{2}:\d{2}:\d{2}$/;
|
|
54
|
+
function localTimeValidator(value, path, ctx) {
|
|
53
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
56
|
return validateLuxon({
|
|
55
57
|
value,
|
|
56
58
|
path,
|
|
57
59
|
ctx,
|
|
58
|
-
type: '
|
|
59
|
-
proto: luxon_2.
|
|
60
|
-
pattern:
|
|
60
|
+
type: 'Time',
|
|
61
|
+
proto: luxon_2.LocalTimeLuxon,
|
|
62
|
+
pattern: timePattern,
|
|
63
|
+
parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
|
|
61
64
|
});
|
|
62
65
|
});
|
|
63
66
|
}
|
|
@@ -70,7 +73,8 @@ function dateTimeValidator(value, path, ctx) {
|
|
|
70
73
|
ctx,
|
|
71
74
|
type: 'DateTime',
|
|
72
75
|
proto: luxon_2.DateTimeLuxon,
|
|
73
|
-
pattern: dateTimePattern
|
|
76
|
+
pattern: dateTimePattern,
|
|
77
|
+
parser: (value) => luxon_1.DateTime.fromISO(value, { setZone: true }),
|
|
74
78
|
});
|
|
75
79
|
});
|
|
76
80
|
}
|
|
@@ -82,7 +86,8 @@ function dateTimeUtcValidator(value, path, ctx) {
|
|
|
82
86
|
ctx,
|
|
83
87
|
type: 'DateTime',
|
|
84
88
|
proto: luxon_2.DateTimeUtcLuxon,
|
|
85
|
-
pattern: dateTimePattern
|
|
89
|
+
pattern: dateTimePattern,
|
|
90
|
+
parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
|
|
86
91
|
});
|
|
87
92
|
});
|
|
88
93
|
}
|
|
@@ -95,7 +100,8 @@ function dateTimeMillisValidator(value, path, ctx) {
|
|
|
95
100
|
ctx,
|
|
96
101
|
type: 'DateTimeMillis',
|
|
97
102
|
proto: luxon_2.DateTimeMillisLuxon,
|
|
98
|
-
pattern: dateTimeMillisPattern
|
|
103
|
+
pattern: dateTimeMillisPattern,
|
|
104
|
+
parser: (value) => luxon_1.DateTime.fromISO(value, { setZone: true }),
|
|
99
105
|
});
|
|
100
106
|
});
|
|
101
107
|
}
|
|
@@ -107,20 +113,8 @@ function dateTimeMillisUtcValidator(value, path, ctx) {
|
|
|
107
113
|
ctx,
|
|
108
114
|
type: 'DateTimeMillis',
|
|
109
115
|
proto: luxon_2.DateTimeMillisUtcLuxon,
|
|
110
|
-
pattern: dateTimeMillisPattern
|
|
111
|
-
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
const timePattern = /^\d{2}:\d{2}:\d{2}$/;
|
|
115
|
-
function timeValidator(value, path, ctx) {
|
|
116
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
return validateLuxon({
|
|
118
|
-
value,
|
|
119
|
-
path,
|
|
120
|
-
ctx,
|
|
121
|
-
type: 'Time',
|
|
122
|
-
proto: luxon_2.TimeLuxon,
|
|
123
|
-
pattern: timePattern
|
|
116
|
+
pattern: dateTimeMillisPattern,
|
|
117
|
+
parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
|
|
124
118
|
});
|
|
125
119
|
});
|
|
126
120
|
}
|
|
@@ -146,12 +140,11 @@ class DurationValidator extends v_validation_1.Validator {
|
|
|
146
140
|
}
|
|
147
141
|
exports.DurationValidator = DurationValidator;
|
|
148
142
|
exports.Vluxon = {
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
localDate: () => v_validation_1.V.fn(localDateValidator),
|
|
144
|
+
localTime: () => v_validation_1.V.fn(localTimeValidator),
|
|
151
145
|
dateTime: () => v_validation_1.V.fn(dateTimeValidator),
|
|
152
146
|
dateTimeUtc: () => v_validation_1.V.fn(dateTimeUtcValidator),
|
|
153
147
|
dateTimeMillis: () => v_validation_1.V.fn(dateTimeMillisValidator),
|
|
154
148
|
dateTimeMillisUtc: () => v_validation_1.V.fn(dateTimeMillisUtcValidator),
|
|
155
|
-
time: () => v_validation_1.V.fn(timeValidator),
|
|
156
149
|
duration: () => new DurationValidator(),
|
|
157
150
|
};
|
package/dist/luxon.d.ts
CHANGED
|
@@ -1,53 +1,60 @@
|
|
|
1
|
-
import { DateTime } from 'luxon';
|
|
1
|
+
import { DateTime, DateTimeJSOptions, DateTimeOptions } from 'luxon';
|
|
2
2
|
export declare type LuxonDateTimeInput = DateTime | LuxonDateTime;
|
|
3
3
|
export declare abstract class LuxonDateTime {
|
|
4
4
|
readonly dateTime: DateTime;
|
|
5
5
|
constructor(input: LuxonDateTimeInput);
|
|
6
|
-
protected normalize(dateTime: DateTime): DateTime;
|
|
6
|
+
protected abstract normalize(dateTime: DateTime): DateTime;
|
|
7
7
|
apply<R>(fn: (dateTime: DateTime) => R): R;
|
|
8
8
|
valueOf(): number;
|
|
9
|
+
as<T extends LuxonDateTime>(type: {
|
|
10
|
+
new (...args: any[]): T;
|
|
11
|
+
}): T;
|
|
9
12
|
equals(other: any): boolean;
|
|
10
13
|
abstract wrap(fn: (dateTime: DateTime) => DateTime): LuxonDateTime;
|
|
11
14
|
abstract toJSON(): string;
|
|
12
15
|
}
|
|
13
|
-
export declare class
|
|
16
|
+
export declare class LocalDateLuxon extends LuxonDateTime {
|
|
14
17
|
static readonly format = "yyyy-MM-dd";
|
|
15
18
|
constructor(input: LuxonDateTimeInput);
|
|
16
|
-
static
|
|
17
|
-
static
|
|
18
|
-
static
|
|
19
|
-
static
|
|
19
|
+
static nowLocal(options?: DateTimeJSOptions): LocalDateLuxon;
|
|
20
|
+
static nowUtc(): LocalDateLuxon;
|
|
21
|
+
static fromISO(value: string, options?: DateTimeOptions): LocalDateLuxon;
|
|
22
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): LocalDateLuxon;
|
|
23
|
+
static fromMillis(millis: number, options?: DateTimeOptions): LocalDateLuxon;
|
|
20
24
|
protected normalize(dateTime: DateTime): DateTime;
|
|
21
|
-
wrap(fn: (dateTime: DateTime) => DateTime):
|
|
25
|
+
wrap(fn: (dateTime: DateTime) => DateTime): LocalDateLuxon;
|
|
22
26
|
toJSON(): string;
|
|
23
27
|
}
|
|
24
|
-
export declare class
|
|
28
|
+
export declare class LocalTimeLuxon extends LuxonDateTime {
|
|
29
|
+
static readonly format = "HH:mm:ss";
|
|
25
30
|
constructor(input: LuxonDateTimeInput);
|
|
26
|
-
static
|
|
27
|
-
static
|
|
28
|
-
static
|
|
29
|
-
static
|
|
31
|
+
static nowLocal(options?: DateTimeJSOptions): LocalTimeLuxon;
|
|
32
|
+
static nowUtc(): LocalTimeLuxon;
|
|
33
|
+
static fromISO(value: string, options?: DateTimeOptions): LocalTimeLuxon;
|
|
34
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): LocalTimeLuxon;
|
|
35
|
+
static fromMillis(millis: number, options?: DateTimeOptions): LocalTimeLuxon;
|
|
30
36
|
protected normalize(dateTime: DateTime): DateTime;
|
|
31
|
-
wrap(fn: (dateTime: DateTime) => DateTime):
|
|
37
|
+
wrap(fn: (dateTime: DateTime) => DateTime): LocalTimeLuxon;
|
|
32
38
|
toJSON(): string;
|
|
33
39
|
}
|
|
34
40
|
export declare class DateTimeLuxon extends LuxonDateTime {
|
|
35
41
|
static readonly format = "yyyy-MM-dd'T'HH:mm:ss";
|
|
36
42
|
static readonly formatTz: string;
|
|
37
43
|
constructor(input: LuxonDateTimeInput);
|
|
38
|
-
static now(): DateTimeLuxon;
|
|
39
|
-
static fromISO(value: string, options?:
|
|
40
|
-
static fromJSDate(date: Date, options?:
|
|
41
|
-
static fromMillis(
|
|
44
|
+
static now(options?: DateTimeJSOptions): DateTimeLuxon;
|
|
45
|
+
static fromISO(value: string, options?: DateTimeOptions): DateTimeLuxon;
|
|
46
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeLuxon;
|
|
47
|
+
static fromMillis(millis: number, options?: DateTimeOptions): DateTimeLuxon;
|
|
48
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
42
49
|
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeLuxon;
|
|
43
50
|
toJSON(): string;
|
|
44
51
|
}
|
|
45
52
|
export declare class DateTimeUtcLuxon extends LuxonDateTime {
|
|
46
53
|
constructor(input: LuxonDateTimeInput);
|
|
47
54
|
static now(): DateTimeUtcLuxon;
|
|
48
|
-
static fromISO(value: string): DateTimeUtcLuxon;
|
|
49
|
-
static fromJSDate(date: Date, options?:
|
|
50
|
-
static fromMillis(
|
|
55
|
+
static fromISO(value: string, options?: DateTimeOptions): DateTimeUtcLuxon;
|
|
56
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeUtcLuxon;
|
|
57
|
+
static fromMillis(millis: number, options?: DateTimeOptions): DateTimeUtcLuxon;
|
|
51
58
|
protected normalize(dateTime: DateTime): DateTime;
|
|
52
59
|
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeUtcLuxon;
|
|
53
60
|
toJSON(): string;
|
|
@@ -56,30 +63,21 @@ export declare class DateTimeMillisLuxon extends LuxonDateTime {
|
|
|
56
63
|
static readonly format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
|
57
64
|
static readonly formatTz: string;
|
|
58
65
|
constructor(input: LuxonDateTimeInput);
|
|
59
|
-
static now(): DateTimeMillisLuxon;
|
|
60
|
-
static fromISO(value: string): DateTimeMillisLuxon;
|
|
61
|
-
static fromJSDate(date: Date, options?:
|
|
62
|
-
static fromMillis(
|
|
66
|
+
static now(options?: DateTimeJSOptions): DateTimeMillisLuxon;
|
|
67
|
+
static fromISO(value: string, options?: DateTimeOptions): DateTimeMillisLuxon;
|
|
68
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeMillisLuxon;
|
|
69
|
+
static fromMillis(millis: number, options?: DateTimeOptions): DateTimeMillisLuxon;
|
|
70
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
63
71
|
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisLuxon;
|
|
64
72
|
toJSON(): string;
|
|
65
73
|
}
|
|
66
74
|
export declare class DateTimeMillisUtcLuxon extends LuxonDateTime {
|
|
67
75
|
constructor(input: LuxonDateTimeInput);
|
|
68
76
|
static now(): DateTimeMillisUtcLuxon;
|
|
69
|
-
static fromISO(value: string, options?:
|
|
70
|
-
static fromJSDate(date: Date, options?:
|
|
71
|
-
static fromMillis(
|
|
77
|
+
static fromISO(value: string, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
|
|
78
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
|
|
79
|
+
static fromMillis(millis: number, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
|
|
72
80
|
protected normalize(dateTime: DateTime): DateTime;
|
|
73
81
|
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisUtcLuxon;
|
|
74
82
|
toJSON(): string;
|
|
75
83
|
}
|
|
76
|
-
export declare class TimeLuxon extends LuxonDateTime {
|
|
77
|
-
static readonly format = "HH:mm:ss";
|
|
78
|
-
constructor(input: LuxonDateTimeInput);
|
|
79
|
-
static now(): TimeLuxon;
|
|
80
|
-
static fromISO(value: string, options?: Object): TimeLuxon;
|
|
81
|
-
static fromJSDate(date: Date, options?: Object): TimeLuxon;
|
|
82
|
-
static fromMillis(milliseconds: number, options?: Object): TimeLuxon;
|
|
83
|
-
wrap(fn: (dateTime: DateTime) => DateTime): TimeLuxon;
|
|
84
|
-
toJSON(): string;
|
|
85
|
-
}
|
package/dist/luxon.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.DateTimeMillisUtcLuxon = exports.DateTimeMillisLuxon = exports.DateTimeUtcLuxon = exports.DateTimeLuxon = exports.LocalTimeLuxon = exports.LocalDateLuxon = exports.LuxonDateTime = void 0;
|
|
5
5
|
const luxon_1 = require("luxon");
|
|
6
6
|
class LuxonDateTime {
|
|
7
7
|
constructor(input) {
|
|
@@ -15,15 +15,18 @@ class LuxonDateTime {
|
|
|
15
15
|
this.dateTime = this.normalize(input);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
normalize(dateTime) {
|
|
19
|
-
return dateTime;
|
|
20
|
-
}
|
|
21
18
|
apply(fn) {
|
|
22
19
|
return fn(this.dateTime);
|
|
23
20
|
}
|
|
24
21
|
valueOf() {
|
|
25
22
|
return this.dateTime.valueOf();
|
|
26
23
|
}
|
|
24
|
+
as(type) {
|
|
25
|
+
if (this instanceof type) {
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
return new type(this.dateTime);
|
|
29
|
+
}
|
|
27
30
|
equals(other) {
|
|
28
31
|
if (this.constructor === other.constructor) {
|
|
29
32
|
return this.dateTime.equals(other.dateTime);
|
|
@@ -32,76 +35,86 @@ class LuxonDateTime {
|
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
exports.LuxonDateTime = LuxonDateTime;
|
|
35
|
-
class
|
|
38
|
+
class LocalDateLuxon extends LuxonDateTime {
|
|
36
39
|
constructor(input) {
|
|
37
40
|
super(input);
|
|
38
41
|
}
|
|
39
|
-
static
|
|
40
|
-
return new
|
|
42
|
+
static nowLocal(options) {
|
|
43
|
+
return new LocalDateLuxon(luxon_1.DateTime.local(options));
|
|
44
|
+
}
|
|
45
|
+
static nowUtc() {
|
|
46
|
+
return new LocalDateLuxon(luxon_1.DateTime.utc());
|
|
41
47
|
}
|
|
42
48
|
static fromISO(value, options) {
|
|
43
|
-
return new
|
|
49
|
+
return new LocalDateLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
44
50
|
}
|
|
45
51
|
static fromJSDate(date, options) {
|
|
46
|
-
return new
|
|
52
|
+
return new LocalDateLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
47
53
|
}
|
|
48
|
-
static fromMillis(
|
|
49
|
-
return new
|
|
54
|
+
static fromMillis(millis, options) {
|
|
55
|
+
return new LocalDateLuxon(luxon_1.DateTime.fromMillis(millis, options));
|
|
50
56
|
}
|
|
51
57
|
normalize(dateTime) {
|
|
52
|
-
return dateTime.
|
|
58
|
+
return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day);
|
|
53
59
|
}
|
|
54
60
|
wrap(fn) {
|
|
55
|
-
return new
|
|
61
|
+
return new LocalDateLuxon(fn(this.dateTime));
|
|
56
62
|
}
|
|
57
63
|
toJSON() {
|
|
58
|
-
return this.dateTime.toFormat(
|
|
64
|
+
return this.dateTime.toFormat(LocalDateLuxon.format);
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
|
-
exports.
|
|
62
|
-
|
|
63
|
-
class
|
|
67
|
+
exports.LocalDateLuxon = LocalDateLuxon;
|
|
68
|
+
LocalDateLuxon.format = 'yyyy-MM-dd';
|
|
69
|
+
class LocalTimeLuxon extends LuxonDateTime {
|
|
64
70
|
constructor(input) {
|
|
65
71
|
super(input);
|
|
66
72
|
}
|
|
67
|
-
static
|
|
68
|
-
return new
|
|
73
|
+
static nowLocal(options) {
|
|
74
|
+
return new LocalTimeLuxon(luxon_1.DateTime.local(options));
|
|
75
|
+
}
|
|
76
|
+
static nowUtc() {
|
|
77
|
+
return new LocalTimeLuxon(luxon_1.DateTime.utc());
|
|
69
78
|
}
|
|
70
79
|
static fromISO(value, options) {
|
|
71
|
-
return new
|
|
80
|
+
return new LocalTimeLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
72
81
|
}
|
|
73
82
|
static fromJSDate(date, options) {
|
|
74
|
-
return new
|
|
83
|
+
return new LocalTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
75
84
|
}
|
|
76
|
-
static fromMillis(
|
|
77
|
-
return new
|
|
85
|
+
static fromMillis(millis, options) {
|
|
86
|
+
return new LocalTimeLuxon(luxon_1.DateTime.fromMillis(millis, options));
|
|
78
87
|
}
|
|
79
88
|
normalize(dateTime) {
|
|
80
|
-
return luxon_1.DateTime.utc(dateTime.
|
|
89
|
+
return luxon_1.DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute, dateTime.second);
|
|
81
90
|
}
|
|
82
91
|
wrap(fn) {
|
|
83
|
-
return new
|
|
92
|
+
return new LocalTimeLuxon(fn(this.dateTime));
|
|
84
93
|
}
|
|
85
94
|
toJSON() {
|
|
86
|
-
return this.dateTime.toFormat(
|
|
95
|
+
return this.dateTime.toFormat(LocalTimeLuxon.format);
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
|
-
exports.
|
|
98
|
+
exports.LocalTimeLuxon = LocalTimeLuxon;
|
|
99
|
+
LocalTimeLuxon.format = 'HH:mm:ss';
|
|
90
100
|
class DateTimeLuxon extends LuxonDateTime {
|
|
91
101
|
constructor(input) {
|
|
92
102
|
super(input);
|
|
93
103
|
}
|
|
94
|
-
static now() {
|
|
95
|
-
return new DateTimeLuxon(luxon_1.DateTime.
|
|
104
|
+
static now(options) {
|
|
105
|
+
return new DateTimeLuxon(luxon_1.DateTime.local(options));
|
|
96
106
|
}
|
|
97
107
|
static fromISO(value, options) {
|
|
98
|
-
return new DateTimeLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
108
|
+
return new DateTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options)));
|
|
99
109
|
}
|
|
100
110
|
static fromJSDate(date, options) {
|
|
101
111
|
return new DateTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
102
112
|
}
|
|
103
|
-
static fromMillis(
|
|
104
|
-
return new DateTimeLuxon(luxon_1.DateTime.fromMillis(
|
|
113
|
+
static fromMillis(millis, options) {
|
|
114
|
+
return new DateTimeLuxon(luxon_1.DateTime.fromMillis(millis, options));
|
|
115
|
+
}
|
|
116
|
+
normalize(dateTime) {
|
|
117
|
+
return dateTime.startOf('second');
|
|
105
118
|
}
|
|
106
119
|
wrap(fn) {
|
|
107
120
|
return new DateTimeLuxon(fn(this.dateTime));
|
|
@@ -122,19 +135,19 @@ class DateTimeUtcLuxon extends LuxonDateTime {
|
|
|
122
135
|
super(input);
|
|
123
136
|
}
|
|
124
137
|
static now() {
|
|
125
|
-
return new DateTimeUtcLuxon(luxon_1.DateTime.
|
|
138
|
+
return new DateTimeUtcLuxon(luxon_1.DateTime.utc());
|
|
126
139
|
}
|
|
127
|
-
static fromISO(value) {
|
|
128
|
-
return new DateTimeUtcLuxon(luxon_1.DateTime.fromISO(value));
|
|
140
|
+
static fromISO(value, options) {
|
|
141
|
+
return new DateTimeUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
|
|
129
142
|
}
|
|
130
143
|
static fromJSDate(date, options) {
|
|
131
|
-
return new DateTimeUtcLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
144
|
+
return new DateTimeUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
|
|
132
145
|
}
|
|
133
|
-
static fromMillis(
|
|
134
|
-
return new DateTimeUtcLuxon(luxon_1.DateTime.fromMillis(
|
|
146
|
+
static fromMillis(millis, options) {
|
|
147
|
+
return new DateTimeUtcLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
|
|
135
148
|
}
|
|
136
149
|
normalize(dateTime) {
|
|
137
|
-
return dateTime.toUTC();
|
|
150
|
+
return dateTime.toUTC().startOf('second');
|
|
138
151
|
}
|
|
139
152
|
wrap(fn) {
|
|
140
153
|
return new DateTimeUtcLuxon(fn(this.dateTime));
|
|
@@ -148,17 +161,20 @@ class DateTimeMillisLuxon extends LuxonDateTime {
|
|
|
148
161
|
constructor(input) {
|
|
149
162
|
super(input);
|
|
150
163
|
}
|
|
151
|
-
static now() {
|
|
152
|
-
return new DateTimeMillisLuxon(luxon_1.DateTime.
|
|
164
|
+
static now(options) {
|
|
165
|
+
return new DateTimeMillisLuxon(luxon_1.DateTime.local(options));
|
|
153
166
|
}
|
|
154
|
-
static fromISO(value) {
|
|
155
|
-
return new DateTimeMillisLuxon(luxon_1.DateTime.fromISO(value));
|
|
167
|
+
static fromISO(value, options) {
|
|
168
|
+
return new DateTimeMillisLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options)));
|
|
156
169
|
}
|
|
157
170
|
static fromJSDate(date, options) {
|
|
158
171
|
return new DateTimeMillisLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
159
172
|
}
|
|
160
|
-
static fromMillis(
|
|
161
|
-
return new DateTimeMillisLuxon(luxon_1.DateTime.fromMillis(
|
|
173
|
+
static fromMillis(millis, options) {
|
|
174
|
+
return new DateTimeMillisLuxon(luxon_1.DateTime.fromMillis(millis, options));
|
|
175
|
+
}
|
|
176
|
+
normalize(dateTime) {
|
|
177
|
+
return dateTime;
|
|
162
178
|
}
|
|
163
179
|
wrap(fn) {
|
|
164
180
|
return new DateTimeMillisLuxon(fn(this.dateTime));
|
|
@@ -179,16 +195,16 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
|
|
|
179
195
|
super(input);
|
|
180
196
|
}
|
|
181
197
|
static now() {
|
|
182
|
-
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.
|
|
198
|
+
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.utc());
|
|
183
199
|
}
|
|
184
200
|
static fromISO(value, options) {
|
|
185
|
-
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
201
|
+
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
|
|
186
202
|
}
|
|
187
203
|
static fromJSDate(date, options) {
|
|
188
|
-
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
204
|
+
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
|
|
189
205
|
}
|
|
190
|
-
static fromMillis(
|
|
191
|
-
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromMillis(
|
|
206
|
+
static fromMillis(millis, options) {
|
|
207
|
+
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
|
|
192
208
|
}
|
|
193
209
|
normalize(dateTime) {
|
|
194
210
|
return dateTime.toUTC();
|
|
@@ -201,28 +217,3 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
|
|
|
201
217
|
}
|
|
202
218
|
}
|
|
203
219
|
exports.DateTimeMillisUtcLuxon = DateTimeMillisUtcLuxon;
|
|
204
|
-
class TimeLuxon extends LuxonDateTime {
|
|
205
|
-
constructor(input) {
|
|
206
|
-
super(input);
|
|
207
|
-
}
|
|
208
|
-
static now() {
|
|
209
|
-
return new TimeLuxon(luxon_1.DateTime.now());
|
|
210
|
-
}
|
|
211
|
-
static fromISO(value, options) {
|
|
212
|
-
return new TimeLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
213
|
-
}
|
|
214
|
-
static fromJSDate(date, options) {
|
|
215
|
-
return new TimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
216
|
-
}
|
|
217
|
-
static fromMillis(milliseconds, options) {
|
|
218
|
-
return new TimeLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
|
|
219
|
-
}
|
|
220
|
-
wrap(fn) {
|
|
221
|
-
return new TimeLuxon(fn(this.dateTime));
|
|
222
|
-
}
|
|
223
|
-
toJSON() {
|
|
224
|
-
return this.dateTime.toFormat(TimeLuxon.format);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
exports.TimeLuxon = TimeLuxon;
|
|
228
|
-
TimeLuxon.format = 'HH:mm:ss';
|
package/dist/test-luxon.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finnair/v-validation-luxon",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Luxon validators",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"build": "tsc -b ."
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@finnair/path": "^1.1.0-alpha.
|
|
29
|
-
"@finnair/v-validation": "^1.1.0-alpha.
|
|
28
|
+
"@finnair/path": "^1.1.0-alpha.6",
|
|
29
|
+
"@finnair/v-validation": "^1.1.0-alpha.6",
|
|
30
30
|
"luxon": "3.0.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/luxon": "3.0.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "b270437f1a403fbb012297653f05d7d6d732fa76"
|
|
36
36
|
}
|