@finnair/v-validation-luxon 1.1.0-alpha.3 → 1.1.0-alpha.6

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,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.6](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.6) (2022-08-17)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Fix exports ([b9eacb6](https://github.com/finnair/v-validation/commit/b9eacb6e98a05a07049eb0a8f97b7e6b4958973a))
12
+
13
+
14
+ ### Features
15
+
16
+ * fromISO helper for Luxon wrapper construction ([e3b8f24](https://github.com/finnair/v-validation/commit/e3b8f247b3a9bfef8ad474688f995862fdd810e3))
17
+ * Support for Luxon ([00d0a8e](https://github.com/finnair/v-validation/commit/00d0a8e8c8de46bfeb3502f51bb8cd5a3627070e))
18
+
19
+
20
+
21
+
22
+
23
+ # [1.1.0-alpha.5](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.5) (2022-08-16)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * Fix exports ([904e63c](https://github.com/finnair/v-validation/commit/904e63c4a40e65d274349ae0f5ea80c697c5c8ce))
29
+
30
+
31
+ ### Features
32
+
33
+ * fromISO helper for Luxon wrapper construction ([81d5b2e](https://github.com/finnair/v-validation/commit/81d5b2eb08f360ab56ec0c6caece392a0e6eb1a1))
34
+ * Support for Luxon ([6a243f0](https://github.com/finnair/v-validation/commit/6a243f043db2ca6700180eb758a08d8edfe1e538))
35
+
36
+
37
+
38
+
39
+
40
+ # [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)
41
+
42
+ **Note:** Version bump only for package @finnair/v-validation-luxon
43
+
44
+
45
+
46
+
47
+
6
48
  # [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)
7
49
 
8
50
  **Note:** Version bump only for package @finnair/v-validation-luxon
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, DateTimeOptions } 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
+ options: DateTimeOptions;
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, options }: 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
- date: () => import("@finnair/v-validation").ValidatorFnWrapper;
20
- dateUtc: () => import("@finnair/v-validation").ValidatorFnWrapper;
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, options }) {
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, options);
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 dateValidator(value, path, ctx) {
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.DateLuxon,
48
- pattern: datePattern
47
+ proto: luxon_2.LocalDateLuxon,
48
+ pattern: datePattern,
49
+ options: { zone: luxon_1.FixedOffsetZone.utcInstance },
49
50
  });
50
51
  });
51
52
  }
52
- function dateUtcValidator(value, path, ctx) {
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: 'Date',
59
- proto: luxon_2.DateUtcLuxon,
60
- pattern: datePattern
60
+ type: 'Time',
61
+ proto: luxon_2.LocalTimeLuxon,
62
+ pattern: timePattern,
63
+ options: { 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
+ options: { 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
+ options: { 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
+ options: { 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
+ options: { 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
- date: () => v_validation_1.V.fn(dateValidator),
150
- dateUtc: () => v_validation_1.V.fn(dateUtcValidator),
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,49 +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 DateLuxon extends LuxonDateTime {
16
+ export declare class LocalDateLuxon extends LuxonDateTime {
14
17
  static readonly format = "yyyy-MM-dd";
15
18
  constructor(input: LuxonDateTimeInput);
16
- static fromISO(value: string, options?: Object): DateLuxon;
17
- static fromJSDate(date: Date, options?: Object): DateLuxon;
18
- static fromMillis(milliseconds: number, options?: Object): DateLuxon;
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;
19
24
  protected normalize(dateTime: DateTime): DateTime;
20
- wrap(fn: (dateTime: DateTime) => DateTime): DateLuxon;
25
+ wrap(fn: (dateTime: DateTime) => DateTime): LocalDateLuxon;
21
26
  toJSON(): string;
22
27
  }
23
- export declare class DateUtcLuxon extends LuxonDateTime {
28
+ export declare class LocalTimeLuxon extends LuxonDateTime {
29
+ static readonly format = "HH:mm:ss";
24
30
  constructor(input: LuxonDateTimeInput);
25
- static fromISO(value: string, options?: Object): DateUtcLuxon;
26
- static fromJSDate(date: Date, options?: Object): DateUtcLuxon;
27
- static fromMillis(milliseconds: number, options?: Object): DateUtcLuxon;
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;
28
36
  protected normalize(dateTime: DateTime): DateTime;
29
- wrap(fn: (dateTime: DateTime) => DateTime): DateUtcLuxon;
37
+ wrap(fn: (dateTime: DateTime) => DateTime): LocalTimeLuxon;
30
38
  toJSON(): string;
31
39
  }
32
40
  export declare class DateTimeLuxon extends LuxonDateTime {
33
41
  static readonly format = "yyyy-MM-dd'T'HH:mm:ss";
34
42
  static readonly formatTz: string;
35
43
  constructor(input: LuxonDateTimeInput);
36
- static fromISO(value: string, options?: Object): DateTimeLuxon;
37
- static fromJSDate(date: Date, options?: Object): DateTimeLuxon;
38
- static fromMillis(milliseconds: number, options?: Object): DateTimeLuxon;
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;
39
49
  wrap(fn: (dateTime: DateTime) => DateTime): DateTimeLuxon;
40
50
  toJSON(): string;
41
51
  }
42
52
  export declare class DateTimeUtcLuxon extends LuxonDateTime {
43
53
  constructor(input: LuxonDateTimeInput);
44
- static fromISO(value: string): DateTimeUtcLuxon;
45
- static fromJSDate(date: Date, options?: Object): DateTimeUtcLuxon;
46
- static fromMillis(milliseconds: number, options?: Object): DateTimeUtcLuxon;
54
+ static now(): DateTimeUtcLuxon;
55
+ static fromISO(value: string, options?: DateTimeOptions): DateTimeUtcLuxon;
56
+ static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeUtcLuxon;
57
+ static fromMillis(millis: number, options?: DateTimeOptions): DateTimeUtcLuxon;
47
58
  protected normalize(dateTime: DateTime): DateTime;
48
59
  wrap(fn: (dateTime: DateTime) => DateTime): DateTimeUtcLuxon;
49
60
  toJSON(): string;
@@ -52,27 +63,21 @@ export declare class DateTimeMillisLuxon extends LuxonDateTime {
52
63
  static readonly format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
53
64
  static readonly formatTz: string;
54
65
  constructor(input: LuxonDateTimeInput);
55
- static fromISO(value: string): DateTimeMillisLuxon;
56
- static fromJSDate(date: Date, options?: Object): DateTimeMillisLuxon;
57
- static fromMillis(milliseconds: number, options?: Object): DateTimeMillisLuxon;
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;
58
71
  wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisLuxon;
59
72
  toJSON(): string;
60
73
  }
61
74
  export declare class DateTimeMillisUtcLuxon extends LuxonDateTime {
62
75
  constructor(input: LuxonDateTimeInput);
63
- static fromISO(value: string, options?: Object): DateTimeMillisUtcLuxon;
64
- static fromJSDate(date: Date, options?: Object): DateTimeMillisUtcLuxon;
65
- static fromMillis(milliseconds: number, options?: Object): DateTimeMillisUtcLuxon;
76
+ static now(): DateTimeMillisUtcLuxon;
77
+ static fromISO(value: string, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
78
+ static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
79
+ static fromMillis(millis: number, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
66
80
  protected normalize(dateTime: DateTime): DateTime;
67
81
  wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisUtcLuxon;
68
82
  toJSON(): string;
69
83
  }
70
- export declare class TimeLuxon extends LuxonDateTime {
71
- static readonly format = "HH:mm:ss";
72
- constructor(input: LuxonDateTimeInput);
73
- static fromISO(value: string, options?: Object): TimeLuxon;
74
- static fromJSDate(date: Date, options?: Object): TimeLuxon;
75
- static fromMillis(milliseconds: number, options?: Object): TimeLuxon;
76
- wrap(fn: (dateTime: DateTime) => DateTime): TimeLuxon;
77
- toJSON(): string;
78
- }
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.TimeLuxon = exports.DateTimeMillisUtcLuxon = exports.DateTimeMillisLuxon = exports.DateTimeUtcLuxon = exports.DateTimeLuxon = exports.DateUtcLuxon = exports.DateLuxon = exports.LuxonDateTime = void 0;
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,67 +32,86 @@ class LuxonDateTime {
32
32
  }
33
33
  }
34
34
  exports.LuxonDateTime = LuxonDateTime;
35
- class DateLuxon extends LuxonDateTime {
35
+ class LocalDateLuxon extends LuxonDateTime {
36
36
  constructor(input) {
37
37
  super(input);
38
38
  }
39
+ static nowLocal(options) {
40
+ return new LocalDateLuxon(luxon_1.DateTime.local(options));
41
+ }
42
+ static nowUtc() {
43
+ return new LocalDateLuxon(luxon_1.DateTime.utc());
44
+ }
39
45
  static fromISO(value, options) {
40
- return new DateLuxon(luxon_1.DateTime.fromISO(value, options));
46
+ return new LocalDateLuxon(luxon_1.DateTime.fromISO(value, options));
41
47
  }
42
48
  static fromJSDate(date, options) {
43
- return new DateLuxon(luxon_1.DateTime.fromJSDate(date, options));
49
+ return new LocalDateLuxon(luxon_1.DateTime.fromJSDate(date, options));
44
50
  }
45
- static fromMillis(milliseconds, options) {
46
- return new DateLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
51
+ static fromMillis(millis, options) {
52
+ return new LocalDateLuxon(luxon_1.DateTime.fromMillis(millis, options));
47
53
  }
48
54
  normalize(dateTime) {
49
- return dateTime.startOf('day');
55
+ return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day);
50
56
  }
51
57
  wrap(fn) {
52
- return new DateLuxon(fn(this.dateTime));
58
+ return new LocalDateLuxon(fn(this.dateTime));
53
59
  }
54
60
  toJSON() {
55
- return this.dateTime.toFormat(DateLuxon.format);
61
+ return this.dateTime.toFormat(LocalDateLuxon.format);
56
62
  }
57
63
  }
58
- exports.DateLuxon = DateLuxon;
59
- DateLuxon.format = 'yyyy-MM-dd';
60
- class DateUtcLuxon extends LuxonDateTime {
64
+ exports.LocalDateLuxon = LocalDateLuxon;
65
+ LocalDateLuxon.format = 'yyyy-MM-dd';
66
+ class LocalTimeLuxon extends LuxonDateTime {
61
67
  constructor(input) {
62
68
  super(input);
63
69
  }
70
+ static nowLocal(options) {
71
+ return new LocalTimeLuxon(luxon_1.DateTime.local(options));
72
+ }
73
+ static nowUtc() {
74
+ return new LocalTimeLuxon(luxon_1.DateTime.utc());
75
+ }
64
76
  static fromISO(value, options) {
65
- return new DateUtcLuxon(luxon_1.DateTime.fromISO(value, options));
77
+ return new LocalTimeLuxon(luxon_1.DateTime.fromISO(value, options));
66
78
  }
67
79
  static fromJSDate(date, options) {
68
- return new DateUtcLuxon(luxon_1.DateTime.fromJSDate(date, options));
80
+ return new LocalTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
69
81
  }
70
- static fromMillis(milliseconds, options) {
71
- return new DateUtcLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
82
+ static fromMillis(millis, options) {
83
+ return new LocalTimeLuxon(luxon_1.DateTime.fromMillis(millis, options));
72
84
  }
73
85
  normalize(dateTime) {
74
- return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day, 0, 0, 0);
86
+ return luxon_1.DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute, dateTime.second);
75
87
  }
76
88
  wrap(fn) {
77
- return new DateUtcLuxon(fn(this.dateTime));
89
+ return new LocalTimeLuxon(fn(this.dateTime));
78
90
  }
79
91
  toJSON() {
80
- return this.dateTime.toFormat(DateLuxon.format);
92
+ return this.dateTime.toFormat(LocalTimeLuxon.format);
81
93
  }
82
94
  }
83
- exports.DateUtcLuxon = DateUtcLuxon;
95
+ exports.LocalTimeLuxon = LocalTimeLuxon;
96
+ LocalTimeLuxon.format = 'HH:mm:ss';
84
97
  class DateTimeLuxon extends LuxonDateTime {
85
98
  constructor(input) {
86
99
  super(input);
87
100
  }
101
+ static now(options) {
102
+ return new DateTimeLuxon(luxon_1.DateTime.local(options));
103
+ }
88
104
  static fromISO(value, options) {
89
- return new DateTimeLuxon(luxon_1.DateTime.fromISO(value, options));
105
+ return new DateTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options)));
90
106
  }
91
107
  static fromJSDate(date, options) {
92
108
  return new DateTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
93
109
  }
94
- static fromMillis(milliseconds, options) {
95
- return new DateTimeLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
110
+ static fromMillis(millis, options) {
111
+ return new DateTimeLuxon(luxon_1.DateTime.fromMillis(millis, options));
112
+ }
113
+ normalize(dateTime) {
114
+ return dateTime.startOf('second');
96
115
  }
97
116
  wrap(fn) {
98
117
  return new DateTimeLuxon(fn(this.dateTime));
@@ -112,17 +131,20 @@ class DateTimeUtcLuxon extends LuxonDateTime {
112
131
  constructor(input) {
113
132
  super(input);
114
133
  }
115
- static fromISO(value) {
116
- return new DateTimeUtcLuxon(luxon_1.DateTime.fromISO(value));
134
+ static now() {
135
+ return new DateTimeUtcLuxon(luxon_1.DateTime.utc());
136
+ }
137
+ static fromISO(value, options) {
138
+ return new DateTimeUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
117
139
  }
118
140
  static fromJSDate(date, options) {
119
- return new DateTimeUtcLuxon(luxon_1.DateTime.fromJSDate(date, options));
141
+ return new DateTimeUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
120
142
  }
121
- static fromMillis(milliseconds, options) {
122
- return new DateTimeUtcLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
143
+ static fromMillis(millis, options) {
144
+ return new DateTimeUtcLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
123
145
  }
124
146
  normalize(dateTime) {
125
- return dateTime.toUTC();
147
+ return dateTime.toUTC().startOf('second');
126
148
  }
127
149
  wrap(fn) {
128
150
  return new DateTimeUtcLuxon(fn(this.dateTime));
@@ -136,14 +158,20 @@ class DateTimeMillisLuxon extends LuxonDateTime {
136
158
  constructor(input) {
137
159
  super(input);
138
160
  }
139
- static fromISO(value) {
140
- return new DateTimeMillisLuxon(luxon_1.DateTime.fromISO(value));
161
+ static now(options) {
162
+ return new DateTimeMillisLuxon(luxon_1.DateTime.local(options));
163
+ }
164
+ static fromISO(value, options) {
165
+ return new DateTimeMillisLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options)));
141
166
  }
142
167
  static fromJSDate(date, options) {
143
168
  return new DateTimeMillisLuxon(luxon_1.DateTime.fromJSDate(date, options));
144
169
  }
145
- static fromMillis(milliseconds, options) {
146
- return new DateTimeMillisLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
170
+ static fromMillis(millis, options) {
171
+ return new DateTimeMillisLuxon(luxon_1.DateTime.fromMillis(millis, options));
172
+ }
173
+ normalize(dateTime) {
174
+ return dateTime;
147
175
  }
148
176
  wrap(fn) {
149
177
  return new DateTimeMillisLuxon(fn(this.dateTime));
@@ -163,14 +191,17 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
163
191
  constructor(input) {
164
192
  super(input);
165
193
  }
194
+ static now() {
195
+ return new DateTimeMillisUtcLuxon(luxon_1.DateTime.utc());
196
+ }
166
197
  static fromISO(value, options) {
167
- return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromISO(value, options));
198
+ return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
168
199
  }
169
200
  static fromJSDate(date, options) {
170
- return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromJSDate(date, options));
201
+ return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
171
202
  }
172
- static fromMillis(milliseconds, options) {
173
- return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
203
+ static fromMillis(millis, options) {
204
+ return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
174
205
  }
175
206
  normalize(dateTime) {
176
207
  return dateTime.toUTC();
@@ -183,25 +214,3 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
183
214
  }
184
215
  }
185
216
  exports.DateTimeMillisUtcLuxon = DateTimeMillisUtcLuxon;
186
- class TimeLuxon extends LuxonDateTime {
187
- constructor(input) {
188
- super(input);
189
- }
190
- static fromISO(value, options) {
191
- return new TimeLuxon(luxon_1.DateTime.fromISO(value, options));
192
- }
193
- static fromJSDate(date, options) {
194
- return new TimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
195
- }
196
- static fromMillis(milliseconds, options) {
197
- return new TimeLuxon(luxon_1.DateTime.fromMillis(milliseconds, options));
198
- }
199
- wrap(fn) {
200
- return new TimeLuxon(fn(this.dateTime));
201
- }
202
- toJSON() {
203
- return this.dateTime.toFormat(TimeLuxon.format);
204
- }
205
- }
206
- exports.TimeLuxon = TimeLuxon;
207
- TimeLuxon.format = 'HH:mm:ss';
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const luxon_1 = require("luxon");
4
- console.log(luxon_1.Duration.fromISO('P3Y6M1W4DT12H30M5S').toJSON());
4
+ const d = luxon_1.DateTime.fromISO('2016-05-25T09:08:34.123');
5
+ console.log(d === d.toUTC());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finnair/v-validation-luxon",
3
- "version": "1.1.0-alpha.3",
3
+ "version": "1.1.0-alpha.6",
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.0",
29
- "@finnair/v-validation": "^1.1.0-alpha.0",
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": "43c45eb094c963918a9dee423abde9090632a595"
35
+ "gitHead": "cbca3585a6777f34cd135c6c22be566aea34e69b"
36
36
  }