@finnair/v-validation-luxon 1.1.0-alpha.5 → 1.1.0-alpha.8

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