@finnair/v-validation-luxon 1.1.0-alpha.2 → 1.1.0-alpha.5
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 +33 -0
- package/dist/Vluxon.d.ts +5 -5
- package/dist/Vluxon.js +15 -26
- package/dist/luxon.d.ts +34 -17
- package/dist/luxon.js +85 -40
- package/dist/test-luxon.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
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.5](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.5) (2022-08-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Fix exports ([904e63c](https://github.com/finnair/v-validation/commit/904e63c4a40e65d274349ae0f5ea80c697c5c8ce))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* fromISO helper for Luxon wrapper construction ([81d5b2e](https://github.com/finnair/v-validation/commit/81d5b2eb08f360ab56ec0c6caece392a0e6eb1a1))
|
|
17
|
+
* Support for Luxon ([6a243f0](https://github.com/finnair/v-validation/commit/6a243f043db2ca6700180eb758a08d8edfe1e538))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# [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)
|
|
24
|
+
|
|
25
|
+
**Note:** Version bump only for package @finnair/v-validation-luxon
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# [1.1.0-alpha.3](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.2...v1.1.0-alpha.3) (2022-08-15)
|
|
32
|
+
|
|
33
|
+
**Note:** Version bump only for package @finnair/v-validation-luxon
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
6
39
|
# [1.1.0-alpha.2](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.1...v1.1.0-alpha.2) (2022-08-12)
|
|
7
40
|
|
|
8
41
|
|
package/dist/Vluxon.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValidationContext, Validator, ValidationResult } from '@finnair/v-validation';
|
|
2
2
|
import { Path } from '@finnair/path';
|
|
3
|
-
import { DateTime } from 'luxon';
|
|
3
|
+
import { DateTime, Zone } from 'luxon';
|
|
4
4
|
import { LuxonDateTime } from './luxon';
|
|
5
5
|
export declare type LuxonInput = string | DateTime | LuxonDateTime;
|
|
6
6
|
export interface ValidateLuxonParams {
|
|
@@ -10,18 +10,18 @@ export interface ValidateLuxonParams {
|
|
|
10
10
|
type: string;
|
|
11
11
|
proto: any;
|
|
12
12
|
pattern: RegExp;
|
|
13
|
+
defaultZone?: Zone;
|
|
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, defaultZone }: 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, defaultZone }) {
|
|
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 = luxon_1.DateTime.fromISO(value, { setZone: true });
|
|
30
|
+
const dateTime = luxon_1.DateTime.fromISO(value, { setZone: true, zone: defaultZone });
|
|
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
|
+
defaultZone: 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
|
+
defaultZone: luxon_1.FixedOffsetZone.utcInstance,
|
|
61
64
|
});
|
|
62
65
|
});
|
|
63
66
|
}
|
|
@@ -70,7 +73,7 @@ function dateTimeValidator(value, path, ctx) {
|
|
|
70
73
|
ctx,
|
|
71
74
|
type: 'DateTime',
|
|
72
75
|
proto: luxon_2.DateTimeLuxon,
|
|
73
|
-
pattern: dateTimePattern
|
|
76
|
+
pattern: dateTimePattern,
|
|
74
77
|
});
|
|
75
78
|
});
|
|
76
79
|
}
|
|
@@ -111,19 +114,6 @@ function dateTimeMillisUtcValidator(value, path, ctx) {
|
|
|
111
114
|
});
|
|
112
115
|
});
|
|
113
116
|
}
|
|
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
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
117
|
const durationPattern = /^P(?!$)(\d+(?:\.\d+)?Y)?(\d+(?:\.\d+)?M)?(\d+(?:\.\d+)?W)?(\d+(?:\.\d+)?D)?(T(?=\d)(\d+(?:\.\d+)?H)?(\d+(?:\.\d+)?M)?(\d+(?:\.\d+)?S)?)?$/;
|
|
128
118
|
class DurationValidator extends v_validation_1.Validator {
|
|
129
119
|
validatePath(value, path, ctx) {
|
|
@@ -146,12 +136,11 @@ class DurationValidator extends v_validation_1.Validator {
|
|
|
146
136
|
}
|
|
147
137
|
exports.DurationValidator = DurationValidator;
|
|
148
138
|
exports.Vluxon = {
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
localDate: () => v_validation_1.V.fn(localDateValidator),
|
|
140
|
+
localTime: () => v_validation_1.V.fn(localTimeValidator),
|
|
151
141
|
dateTime: () => v_validation_1.V.fn(dateTimeValidator),
|
|
152
142
|
dateTimeUtc: () => v_validation_1.V.fn(dateTimeUtcValidator),
|
|
153
143
|
dateTimeMillis: () => v_validation_1.V.fn(dateTimeMillisValidator),
|
|
154
144
|
dateTimeMillisUtc: () => v_validation_1.V.fn(dateTimeMillisUtcValidator),
|
|
155
|
-
time: () => v_validation_1.V.fn(timeValidator),
|
|
156
145
|
duration: () => new DurationValidator(),
|
|
157
146
|
};
|
package/dist/luxon.d.ts
CHANGED
|
@@ -1,41 +1,58 @@
|
|
|
1
|
-
import { DateTime } from 'luxon';
|
|
1
|
+
import { DateTime, 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
|
|
19
|
+
static now(): LocalDateLuxon;
|
|
20
|
+
static fromISO(value: string, options?: DateTimeOptions): LocalDateLuxon;
|
|
21
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): LocalDateLuxon;
|
|
22
|
+
static fromMillis(milliseconds: number, options?: DateTimeOptions): LocalDateLuxon;
|
|
17
23
|
protected normalize(dateTime: DateTime): DateTime;
|
|
18
|
-
wrap(fn: (dateTime: DateTime) => DateTime):
|
|
24
|
+
wrap(fn: (dateTime: DateTime) => DateTime): LocalDateLuxon;
|
|
19
25
|
toJSON(): string;
|
|
20
26
|
}
|
|
21
|
-
export declare class
|
|
27
|
+
export declare class LocalTimeLuxon extends LuxonDateTime {
|
|
28
|
+
static readonly format = "HH:mm:ss";
|
|
22
29
|
constructor(input: LuxonDateTimeInput);
|
|
23
|
-
static
|
|
30
|
+
static now(): LocalTimeLuxon;
|
|
31
|
+
static fromISO(value: string, options?: DateTimeOptions): LocalTimeLuxon;
|
|
32
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): LocalTimeLuxon;
|
|
33
|
+
static fromMillis(milliseconds: number, options?: DateTimeOptions): LocalTimeLuxon;
|
|
24
34
|
protected normalize(dateTime: DateTime): DateTime;
|
|
25
|
-
wrap(fn: (dateTime: DateTime) => DateTime):
|
|
35
|
+
wrap(fn: (dateTime: DateTime) => DateTime): LocalTimeLuxon;
|
|
26
36
|
toJSON(): string;
|
|
27
37
|
}
|
|
28
38
|
export declare class DateTimeLuxon extends LuxonDateTime {
|
|
29
39
|
static readonly format = "yyyy-MM-dd'T'HH:mm:ss";
|
|
30
40
|
static readonly formatTz: string;
|
|
31
41
|
constructor(input: LuxonDateTimeInput);
|
|
32
|
-
static
|
|
42
|
+
static now(): DateTimeLuxon;
|
|
43
|
+
static fromISO(value: string, options?: DateTimeOptions): DateTimeLuxon;
|
|
44
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeLuxon;
|
|
45
|
+
static fromMillis(milliseconds: number, options?: DateTimeOptions): DateTimeLuxon;
|
|
46
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
33
47
|
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeLuxon;
|
|
34
48
|
toJSON(): string;
|
|
35
49
|
}
|
|
36
50
|
export declare class DateTimeUtcLuxon extends LuxonDateTime {
|
|
37
51
|
constructor(input: LuxonDateTimeInput);
|
|
52
|
+
static now(): DateTimeUtcLuxon;
|
|
38
53
|
static fromISO(value: string): DateTimeUtcLuxon;
|
|
54
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeUtcLuxon;
|
|
55
|
+
static fromMillis(milliseconds: number, options?: DateTimeOptions): DateTimeUtcLuxon;
|
|
39
56
|
protected normalize(dateTime: DateTime): DateTime;
|
|
40
57
|
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeUtcLuxon;
|
|
41
58
|
toJSON(): string;
|
|
@@ -44,21 +61,21 @@ export declare class DateTimeMillisLuxon extends LuxonDateTime {
|
|
|
44
61
|
static readonly format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
|
45
62
|
static readonly formatTz: string;
|
|
46
63
|
constructor(input: LuxonDateTimeInput);
|
|
64
|
+
static now(): DateTimeMillisLuxon;
|
|
47
65
|
static fromISO(value: string): DateTimeMillisLuxon;
|
|
66
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeMillisLuxon;
|
|
67
|
+
static fromMillis(milliseconds: number, options?: DateTimeOptions): DateTimeMillisLuxon;
|
|
68
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
48
69
|
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisLuxon;
|
|
49
70
|
toJSON(): string;
|
|
50
71
|
}
|
|
51
72
|
export declare class DateTimeMillisUtcLuxon extends LuxonDateTime {
|
|
52
73
|
constructor(input: LuxonDateTimeInput);
|
|
53
|
-
static
|
|
74
|
+
static now(): DateTimeMillisUtcLuxon;
|
|
75
|
+
static fromISO(value: string, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
|
|
76
|
+
static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
|
|
77
|
+
static fromMillis(milliseconds: number, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
|
|
54
78
|
protected normalize(dateTime: DateTime): DateTime;
|
|
55
79
|
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisUtcLuxon;
|
|
56
80
|
toJSON(): string;
|
|
57
81
|
}
|
|
58
|
-
export declare class TimeLuxon extends LuxonDateTime {
|
|
59
|
-
static readonly format = "HH:mm:ss";
|
|
60
|
-
constructor(input: LuxonDateTimeInput);
|
|
61
|
-
static fromISO(value: string): TimeLuxon;
|
|
62
|
-
wrap(fn: (dateTime: DateTime) => DateTime): TimeLuxon;
|
|
63
|
-
toJSON(): string;
|
|
64
|
-
}
|
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,15 @@ 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
|
+
return new type(this.dateTime);
|
|
26
|
+
}
|
|
27
27
|
equals(other) {
|
|
28
28
|
if (this.constructor === other.constructor) {
|
|
29
29
|
return this.dateTime.equals(other.dateTime);
|
|
@@ -32,49 +32,80 @@ class LuxonDateTime {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
exports.LuxonDateTime = LuxonDateTime;
|
|
35
|
-
class
|
|
35
|
+
class LocalDateLuxon extends LuxonDateTime {
|
|
36
36
|
constructor(input) {
|
|
37
37
|
super(input);
|
|
38
38
|
}
|
|
39
|
-
static
|
|
40
|
-
return new
|
|
39
|
+
static now() {
|
|
40
|
+
return new LocalDateLuxon(luxon_1.DateTime.now());
|
|
41
|
+
}
|
|
42
|
+
static fromISO(value, options) {
|
|
43
|
+
return new LocalDateLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
44
|
+
}
|
|
45
|
+
static fromJSDate(date, options) {
|
|
46
|
+
return new LocalDateLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
47
|
+
}
|
|
48
|
+
static fromMillis(milliseconds, options) {
|
|
49
|
+
return new LocalDateLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
|
|
41
50
|
}
|
|
42
51
|
normalize(dateTime) {
|
|
43
|
-
return dateTime.
|
|
52
|
+
return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day);
|
|
44
53
|
}
|
|
45
54
|
wrap(fn) {
|
|
46
|
-
return new
|
|
55
|
+
return new LocalDateLuxon(fn(this.dateTime));
|
|
47
56
|
}
|
|
48
57
|
toJSON() {
|
|
49
|
-
return this.dateTime.toFormat(
|
|
58
|
+
return this.dateTime.toFormat(LocalDateLuxon.format);
|
|
50
59
|
}
|
|
51
60
|
}
|
|
52
|
-
exports.
|
|
53
|
-
|
|
54
|
-
class
|
|
61
|
+
exports.LocalDateLuxon = LocalDateLuxon;
|
|
62
|
+
LocalDateLuxon.format = 'yyyy-MM-dd';
|
|
63
|
+
class LocalTimeLuxon extends LuxonDateTime {
|
|
55
64
|
constructor(input) {
|
|
56
65
|
super(input);
|
|
57
66
|
}
|
|
58
|
-
static
|
|
59
|
-
return new
|
|
67
|
+
static now() {
|
|
68
|
+
return new LocalTimeLuxon(luxon_1.DateTime.now());
|
|
69
|
+
}
|
|
70
|
+
static fromISO(value, options) {
|
|
71
|
+
return new LocalTimeLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
72
|
+
}
|
|
73
|
+
static fromJSDate(date, options) {
|
|
74
|
+
return new LocalTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
75
|
+
}
|
|
76
|
+
static fromMillis(milliseconds, options) {
|
|
77
|
+
return new LocalTimeLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
|
|
60
78
|
}
|
|
61
79
|
normalize(dateTime) {
|
|
62
|
-
return luxon_1.DateTime.utc(dateTime.
|
|
80
|
+
return luxon_1.DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute, dateTime.second);
|
|
63
81
|
}
|
|
64
82
|
wrap(fn) {
|
|
65
|
-
return new
|
|
83
|
+
return new LocalTimeLuxon(fn(this.dateTime));
|
|
66
84
|
}
|
|
67
85
|
toJSON() {
|
|
68
|
-
return this.dateTime.toFormat(
|
|
86
|
+
return this.dateTime.toFormat(LocalTimeLuxon.format);
|
|
69
87
|
}
|
|
70
88
|
}
|
|
71
|
-
exports.
|
|
89
|
+
exports.LocalTimeLuxon = LocalTimeLuxon;
|
|
90
|
+
LocalTimeLuxon.format = 'HH:mm:ss';
|
|
72
91
|
class DateTimeLuxon extends LuxonDateTime {
|
|
73
92
|
constructor(input) {
|
|
74
93
|
super(input);
|
|
75
94
|
}
|
|
76
|
-
static
|
|
77
|
-
return new DateTimeLuxon(luxon_1.DateTime.
|
|
95
|
+
static now() {
|
|
96
|
+
return new DateTimeLuxon(luxon_1.DateTime.now());
|
|
97
|
+
}
|
|
98
|
+
static fromISO(value, options) {
|
|
99
|
+
return new DateTimeLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
100
|
+
}
|
|
101
|
+
static fromJSDate(date, options) {
|
|
102
|
+
return new DateTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
103
|
+
}
|
|
104
|
+
static fromMillis(milliseconds, options) {
|
|
105
|
+
return new DateTimeLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
|
|
106
|
+
}
|
|
107
|
+
normalize(dateTime) {
|
|
108
|
+
return dateTime.startOf('second');
|
|
78
109
|
}
|
|
79
110
|
wrap(fn) {
|
|
80
111
|
return new DateTimeLuxon(fn(this.dateTime));
|
|
@@ -94,11 +125,20 @@ class DateTimeUtcLuxon extends LuxonDateTime {
|
|
|
94
125
|
constructor(input) {
|
|
95
126
|
super(input);
|
|
96
127
|
}
|
|
128
|
+
static now() {
|
|
129
|
+
return new DateTimeUtcLuxon(luxon_1.DateTime.now());
|
|
130
|
+
}
|
|
97
131
|
static fromISO(value) {
|
|
98
132
|
return new DateTimeUtcLuxon(luxon_1.DateTime.fromISO(value));
|
|
99
133
|
}
|
|
134
|
+
static fromJSDate(date, options) {
|
|
135
|
+
return new DateTimeUtcLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
136
|
+
}
|
|
137
|
+
static fromMillis(milliseconds, options) {
|
|
138
|
+
return new DateTimeUtcLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
|
|
139
|
+
}
|
|
100
140
|
normalize(dateTime) {
|
|
101
|
-
return dateTime.toUTC();
|
|
141
|
+
return dateTime.toUTC().startOf('second');
|
|
102
142
|
}
|
|
103
143
|
wrap(fn) {
|
|
104
144
|
return new DateTimeUtcLuxon(fn(this.dateTime));
|
|
@@ -112,9 +152,21 @@ class DateTimeMillisLuxon extends LuxonDateTime {
|
|
|
112
152
|
constructor(input) {
|
|
113
153
|
super(input);
|
|
114
154
|
}
|
|
155
|
+
static now() {
|
|
156
|
+
return new DateTimeMillisLuxon(luxon_1.DateTime.now());
|
|
157
|
+
}
|
|
115
158
|
static fromISO(value) {
|
|
116
159
|
return new DateTimeMillisLuxon(luxon_1.DateTime.fromISO(value));
|
|
117
160
|
}
|
|
161
|
+
static fromJSDate(date, options) {
|
|
162
|
+
return new DateTimeMillisLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
163
|
+
}
|
|
164
|
+
static fromMillis(milliseconds, options) {
|
|
165
|
+
return new DateTimeMillisLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
|
|
166
|
+
}
|
|
167
|
+
normalize(dateTime) {
|
|
168
|
+
return dateTime;
|
|
169
|
+
}
|
|
118
170
|
wrap(fn) {
|
|
119
171
|
return new DateTimeMillisLuxon(fn(this.dateTime));
|
|
120
172
|
}
|
|
@@ -133,8 +185,17 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
|
|
|
133
185
|
constructor(input) {
|
|
134
186
|
super(input);
|
|
135
187
|
}
|
|
136
|
-
static
|
|
137
|
-
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.
|
|
188
|
+
static now() {
|
|
189
|
+
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.now());
|
|
190
|
+
}
|
|
191
|
+
static fromISO(value, options) {
|
|
192
|
+
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromISO(value, options));
|
|
193
|
+
}
|
|
194
|
+
static fromJSDate(date, options) {
|
|
195
|
+
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromJSDate(date, options));
|
|
196
|
+
}
|
|
197
|
+
static fromMillis(milliseconds, options) {
|
|
198
|
+
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
|
|
138
199
|
}
|
|
139
200
|
normalize(dateTime) {
|
|
140
201
|
return dateTime.toUTC();
|
|
@@ -147,19 +208,3 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
|
|
|
147
208
|
}
|
|
148
209
|
}
|
|
149
210
|
exports.DateTimeMillisUtcLuxon = DateTimeMillisUtcLuxon;
|
|
150
|
-
class TimeLuxon extends LuxonDateTime {
|
|
151
|
-
constructor(input) {
|
|
152
|
-
super(input);
|
|
153
|
-
}
|
|
154
|
-
static fromISO(value) {
|
|
155
|
-
return new TimeLuxon(luxon_1.DateTime.fromISO(value));
|
|
156
|
-
}
|
|
157
|
-
wrap(fn) {
|
|
158
|
-
return new TimeLuxon(fn(this.dateTime));
|
|
159
|
-
}
|
|
160
|
-
toJSON() {
|
|
161
|
-
return this.dateTime.toFormat(TimeLuxon.format);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.TimeLuxon = TimeLuxon;
|
|
165
|
-
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.5",
|
|
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.5",
|
|
29
|
+
"@finnair/v-validation": "^1.1.0-alpha.5",
|
|
30
30
|
"luxon": "3.0.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/luxon": "3.0.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "593b0dc9cb646a7059d2ede95c44c3b80bec51d3"
|
|
36
36
|
}
|