@finnair/v-validation-luxon 3.0.0-alpha.2 → 3.1.0

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,171 +3,105 @@
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
- # [3.0.0-alpha.2](https://github.com/finnair/v-validation/compare/v2.0.0...v3.0.0-alpha.2) (2022-09-28)
6
+ # [3.1.0](https://github.com/finnair/v-validation/compare/v3.0.0...v3.1.0) (2022-10-24)
7
7
 
8
8
 
9
9
  ### Features
10
10
 
11
- * Use SyncPromise also in schema and luxon ([792fbb4](https://github.com/finnair/v-validation/commit/792fbb4c78d07ea085d669312fef5e44e7a397fd))
11
+ * LocalDateTimeLuxon (a date-time without timezone) ([#83](https://github.com/finnair/v-validation/issues/83)) ([1517c6e](https://github.com/finnair/v-validation/commit/1517c6ec8af835cb928cd6cf228b9bdc9f0cda3e))
12
12
 
13
13
 
14
14
 
15
15
 
16
16
 
17
- # [3.0.0-alpha.1](https://github.com/finnair/v-validation/compare/v2.0.0...v3.0.0-alpha.1) (2022-09-26)
18
-
17
+ # [3.0.0](https://github.com/finnair/v-validation/compare/v2.0.0...v3.0.0) (2022-10-03)
19
18
 
20
19
  ### Features
21
20
 
22
- * Use SyncPromise also in schema and luxon ([792fbb4](https://github.com/finnair/v-validation/commit/792fbb4c78d07ea085d669312fef5e44e7a397fd))
23
-
24
-
25
-
26
-
27
-
28
- # [3.0.0-alpha.0](https://github.com/finnair/v-validation/compare/v2.0.0...v3.0.0-alpha.0) (2022-09-26)
29
-
30
-
31
- ### Features
32
-
33
- * Use SyncPromise also in schema and luxon ([e8590b8](https://github.com/finnair/v-validation/commit/e8590b8c2a44ad28fde88f8682f53628ecf74a0f))
34
-
35
-
21
+ - Optimize performance.
22
+ - Use Object.freeze to ensure Validator immutability.
36
23
 
24
+ ### BREAKING CHANGES
37
25
 
26
+ - LuxonValidator class instead of validateLuxon function.
38
27
 
39
28
  # [2.0.0](https://github.com/finnair/v-validation/compare/v1.1.0...v2.0.0) (2022-09-08)
40
29
 
41
-
42
- * Upgrade All Dependencies (#80) ([fb6309c](https://github.com/finnair/v-validation/commit/fb6309cc1d9fd90f3e8c5ba79798fae1450b66a6)), closes [#80](https://github.com/finnair/v-validation/issues/80)
43
-
30
+ - Upgrade All Dependencies (#80) ([fb6309c](https://github.com/finnair/v-validation/commit/fb6309cc1d9fd90f3e8c5ba79798fae1450b66a6)), closes [#80](https://github.com/finnair/v-validation/issues/80)
44
31
 
45
32
  ### Features
46
33
 
47
- * Implement toString in Luxon wrapper types ([#79](https://github.com/finnair/v-validation/issues/79)) ([3f3f3e8](https://github.com/finnair/v-validation/commit/3f3f3e8a4172c7803a7be4809f06aba554f7090f))
48
-
34
+ - Implement toString in Luxon wrapper types ([#79](https://github.com/finnair/v-validation/issues/79)) ([3f3f3e8](https://github.com/finnair/v-validation/commit/3f3f3e8a4172c7803a7be4809f06aba554f7090f))
49
35
 
50
36
  ### BREAKING CHANGES
51
37
 
52
- * Drop Node 12 support
53
- * Add .nvmrc
54
- * Introduce CI build for Node 18
55
- * Upgrade All Dependencies
56
-
57
-
58
-
59
-
38
+ - Drop Node 12 support
39
+ - Add .nvmrc
40
+ - Introduce CI build for Node 18
41
+ - Upgrade All Dependencies
60
42
 
61
43
  # [1.1.0](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0) (2022-08-29)
62
44
 
63
-
64
45
  ### Features
65
46
 
66
- * Support for Luxon ([94b3806](https://github.com/finnair/v-validation/commit/94b38060e07feeb0abb8c81659d8bda537a4d9aa))
67
-
68
-
69
-
70
-
47
+ - Support for Luxon ([94b3806](https://github.com/finnair/v-validation/commit/94b38060e07feeb0abb8c81659d8bda537a4d9aa))
71
48
 
72
49
  # [1.1.0-alpha.9](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.8...v1.1.0-alpha.9) (2022-08-19)
73
50
 
74
51
  **Note:** Version bump only for package @finnair/v-validation-luxon
75
52
 
76
-
77
-
78
-
79
-
80
53
  # [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)
81
54
 
82
55
  **Note:** Version bump only for package @finnair/v-validation-luxon
83
56
 
84
-
85
-
86
-
87
-
88
57
  # [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)
89
58
 
90
59
  **Note:** Version bump only for package @finnair/v-validation-luxon
91
60
 
92
-
93
-
94
-
95
-
96
61
  # [1.1.0-alpha.6](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.6) (2022-08-17)
97
62
 
98
-
99
63
  ### Bug Fixes
100
64
 
101
- * Fix exports ([b9eacb6](https://github.com/finnair/v-validation/commit/b9eacb6e98a05a07049eb0a8f97b7e6b4958973a))
102
-
65
+ - Fix exports ([b9eacb6](https://github.com/finnair/v-validation/commit/b9eacb6e98a05a07049eb0a8f97b7e6b4958973a))
103
66
 
104
67
  ### Features
105
68
 
106
- * fromISO helper for Luxon wrapper construction ([e3b8f24](https://github.com/finnair/v-validation/commit/e3b8f247b3a9bfef8ad474688f995862fdd810e3))
107
- * Support for Luxon ([00d0a8e](https://github.com/finnair/v-validation/commit/00d0a8e8c8de46bfeb3502f51bb8cd5a3627070e))
108
-
109
-
110
-
111
-
69
+ - fromISO helper for Luxon wrapper construction ([e3b8f24](https://github.com/finnair/v-validation/commit/e3b8f247b3a9bfef8ad474688f995862fdd810e3))
70
+ - Support for Luxon ([00d0a8e](https://github.com/finnair/v-validation/commit/00d0a8e8c8de46bfeb3502f51bb8cd5a3627070e))
112
71
 
113
72
  # [1.1.0-alpha.5](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.5) (2022-08-16)
114
73
 
115
-
116
74
  ### Bug Fixes
117
75
 
118
- * Fix exports ([904e63c](https://github.com/finnair/v-validation/commit/904e63c4a40e65d274349ae0f5ea80c697c5c8ce))
119
-
76
+ - Fix exports ([904e63c](https://github.com/finnair/v-validation/commit/904e63c4a40e65d274349ae0f5ea80c697c5c8ce))
120
77
 
121
78
  ### Features
122
79
 
123
- * fromISO helper for Luxon wrapper construction ([81d5b2e](https://github.com/finnair/v-validation/commit/81d5b2eb08f360ab56ec0c6caece392a0e6eb1a1))
124
- * Support for Luxon ([6a243f0](https://github.com/finnair/v-validation/commit/6a243f043db2ca6700180eb758a08d8edfe1e538))
125
-
126
-
127
-
128
-
80
+ - fromISO helper for Luxon wrapper construction ([81d5b2e](https://github.com/finnair/v-validation/commit/81d5b2eb08f360ab56ec0c6caece392a0e6eb1a1))
81
+ - Support for Luxon ([6a243f0](https://github.com/finnair/v-validation/commit/6a243f043db2ca6700180eb758a08d8edfe1e538))
129
82
 
130
83
  # [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)
131
84
 
132
85
  **Note:** Version bump only for package @finnair/v-validation-luxon
133
86
 
134
-
135
-
136
-
137
-
138
87
  # [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)
139
88
 
140
89
  **Note:** Version bump only for package @finnair/v-validation-luxon
141
90
 
142
-
143
-
144
-
145
-
146
91
  # [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)
147
92
 
148
-
149
93
  ### Bug Fixes
150
94
 
151
- * Fix exports ([c4c42f7](https://github.com/finnair/v-validation/commit/c4c42f715e8c52b29b76f7f07753f632528a69ab))
152
-
153
-
154
-
155
-
95
+ - Fix exports ([c4c42f7](https://github.com/finnair/v-validation/commit/c4c42f715e8c52b29b76f7f07753f632528a69ab))
156
96
 
157
97
  # [1.1.0-alpha.1](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.0...v1.1.0-alpha.1) (2022-08-12)
158
98
 
159
-
160
99
  ### Features
161
100
 
162
- * fromISO helper for Luxon wrapper construction ([187796e](https://github.com/finnair/v-validation/commit/187796e707f44033d94943ef64d48626317b4d80))
163
-
164
-
165
-
166
-
101
+ - fromISO helper for Luxon wrapper construction ([187796e](https://github.com/finnair/v-validation/commit/187796e707f44033d94943ef64d48626317b4d80))
167
102
 
168
103
  # [1.1.0-alpha.0](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.0) (2022-08-12)
169
104
 
170
-
171
105
  ### Features
172
106
 
173
- * Support for Luxon ([6f982df](https://github.com/finnair/v-validation/commit/6f982df9b55395e953069914c93fef677dec171e))
107
+ - Support for Luxon ([6f982df](https://github.com/finnair/v-validation/commit/6f982df9b55395e953069914c93fef677dec171e))
package/dist/Vluxon.d.ts CHANGED
@@ -4,25 +4,27 @@ import { DateTime, DateTimeJSOptions, DateTimeOptions } from 'luxon';
4
4
  import { LuxonDateTime } from './luxon';
5
5
  export declare type LuxonInput = string | DateTime | LuxonDateTime;
6
6
  export interface ValidateLuxonParams {
7
- value: any;
8
- path: Path;
9
- ctx: ValidationContext;
10
7
  type: string;
11
8
  pattern: RegExp;
12
9
  proto?: any;
13
10
  parser: (value: string, match: RegExpExecArray) => DateTime;
14
11
  }
15
- export declare function validateLuxon({ value, path, ctx, type, proto, pattern, parser }: ValidateLuxonParams): PromiseLike<ValidationResult>;
16
- declare function localDate(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
17
- declare function localTime(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
18
- declare function dateTime(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
19
- declare function dateTimeUtc(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
20
- declare function dateTimeMillis(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
21
- declare function dateTimeMillisUtc(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
22
- declare function dateTimeFromISO(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
23
- declare function dateTimeFromRFC2822(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
24
- declare function dateTimeFromHTTP(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
25
- declare function dateTimeFromSQL(options?: DateTimeOptions): import("@finnair/v-validation").ValidatorFnWrapper;
12
+ export declare class LuxonValidator extends Validator {
13
+ params: ValidateLuxonParams;
14
+ constructor(params: ValidateLuxonParams);
15
+ validatePath(value: any, path: Path, ctx: ValidationContext): PromiseLike<ValidationResult>;
16
+ }
17
+ declare function localDate(options?: DateTimeOptions): LuxonValidator;
18
+ declare function localTime(options?: DateTimeOptions): LuxonValidator;
19
+ declare function localDateTime(options?: DateTimeOptions): LuxonValidator;
20
+ declare function dateTime(options?: DateTimeOptions): LuxonValidator;
21
+ declare function dateTimeUtc(options?: DateTimeOptions): LuxonValidator;
22
+ declare function dateTimeMillis(options?: DateTimeOptions): LuxonValidator;
23
+ declare function dateTimeMillisUtc(options?: DateTimeOptions): LuxonValidator;
24
+ declare function dateTimeFromISO(options?: DateTimeOptions): LuxonValidator;
25
+ declare function dateTimeFromRFC2822(options?: DateTimeOptions): LuxonValidator;
26
+ declare function dateTimeFromHTTP(options?: DateTimeOptions): LuxonValidator;
27
+ declare function dateTimeFromSQL(options?: DateTimeOptions): LuxonValidator;
26
28
  export interface ValidateLuxonNumberParams {
27
29
  value: any;
28
30
  path: Path;
@@ -39,6 +41,7 @@ export declare class DurationValidator extends Validator {
39
41
  export declare const Vluxon: {
40
42
  localDate: typeof localDate;
41
43
  localTime: typeof localTime;
44
+ localDateTime: typeof localDateTime;
42
45
  dateTime: typeof dateTime;
43
46
  dateTimeUtc: typeof dateTimeUtc;
44
47
  dateTimeMillis: typeof dateTimeMillis;
package/dist/Vluxon.js CHANGED
@@ -9,146 +9,134 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Vluxon = exports.DurationValidator = exports.validateLuxonNumber = exports.validateLuxon = void 0;
12
+ exports.Vluxon = exports.DurationValidator = exports.validateLuxonNumber = exports.LuxonValidator = 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, parser }) {
17
- if ((0, v_validation_1.isNullOrUndefined)(value)) {
18
- return ctx.failurePromise(v_validation_1.defaultViolations.notNull(path), value);
16
+ class LuxonValidator extends v_validation_1.Validator {
17
+ constructor(params) {
18
+ super();
19
+ this.params = params;
20
+ Object.freeze(params);
21
+ Object.freeze(this);
19
22
  }
20
- if (proto && value instanceof proto) {
21
- return ctx.successPromise(value);
22
- }
23
- else if (luxon_1.DateTime.isDateTime(value)) {
24
- if (value.isValid) {
25
- return success(value);
23
+ validatePath(value, path, ctx) {
24
+ const params = this.params;
25
+ if ((0, v_validation_1.isNullOrUndefined)(value)) {
26
+ return ctx.failurePromise(v_validation_1.defaultViolations.notNull(path), value);
26
27
  }
27
- }
28
- else if ((0, v_validation_1.isString)(value)) {
29
- const match = pattern.exec(value);
30
- if (match) {
31
- const dateTime = parser(value, match);
32
- if (dateTime.isValid) {
33
- return success(dateTime);
28
+ if (params.proto && value instanceof params.proto) {
29
+ return ctx.successPromise(value);
30
+ }
31
+ else if (luxon_1.DateTime.isDateTime(value)) {
32
+ if (value.isValid) {
33
+ return success(value);
34
34
  }
35
35
  }
36
- }
37
- return ctx.failurePromise(v_validation_1.defaultViolations.date(value, path, type), value);
38
- function success(dateTime) {
39
- return ctx.successPromise(proto ? new proto(dateTime) : dateTime);
36
+ else if ((0, v_validation_1.isString)(value)) {
37
+ const match = params.pattern.exec(value);
38
+ if (match) {
39
+ const dateTime = params.parser(value, match);
40
+ if (dateTime.isValid) {
41
+ return success(dateTime);
42
+ }
43
+ }
44
+ }
45
+ return ctx.failurePromise(v_validation_1.defaultViolations.date(value, path, params.type), value);
46
+ function success(dateTime) {
47
+ return ctx.successPromise(params.proto ? new params.proto(dateTime) : dateTime);
48
+ }
40
49
  }
41
50
  }
42
- exports.validateLuxon = validateLuxon;
51
+ exports.LuxonValidator = LuxonValidator;
43
52
  const datePattern = /^\d{4}-\d{2}-\d{2}$/;
44
53
  function localDate(options = { setZone: true }) {
45
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
46
- value,
47
- path,
48
- ctx,
54
+ return new LuxonValidator({
49
55
  type: 'Date',
50
56
  proto: luxon_2.LocalDateLuxon,
51
57
  pattern: datePattern,
52
58
  parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
53
- }));
59
+ });
54
60
  }
55
61
  const timePattern = /^\d{2}:\d{2}:\d{2}$/;
56
62
  function localTime(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
57
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
58
- value,
59
- path,
60
- ctx,
63
+ return new LuxonValidator({
61
64
  type: 'Time',
62
65
  proto: luxon_2.LocalTimeLuxon,
63
66
  pattern: timePattern,
64
67
  parser: (value) => luxon_1.DateTime.fromISO(value, options),
65
- }));
68
+ });
66
69
  }
67
- const dateTimePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
70
+ const localDateTimePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
71
+ function localDateTime(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
72
+ return new LuxonValidator({
73
+ type: 'DateTime',
74
+ proto: luxon_2.LocalDateTimeLuxon,
75
+ pattern: localDateTimePattern,
76
+ parser: (value) => luxon_1.DateTime.fromISO(value, options),
77
+ });
78
+ }
79
+ const dateTimeTzPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
68
80
  function dateTime(options = { setZone: true }) {
69
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
70
- value,
71
- path,
72
- ctx,
81
+ return new LuxonValidator({
73
82
  type: 'DateTime',
74
83
  proto: luxon_2.DateTimeLuxon,
75
- pattern: dateTimePattern,
84
+ pattern: dateTimeTzPattern,
76
85
  parser: (value) => luxon_1.DateTime.fromISO(value, options),
77
- }));
86
+ });
78
87
  }
79
88
  function dateTimeUtc(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
80
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
81
- value,
82
- path,
83
- ctx,
89
+ return new LuxonValidator({
84
90
  type: 'DateTime',
85
91
  proto: luxon_2.DateTimeUtcLuxon,
86
- pattern: dateTimePattern,
92
+ pattern: dateTimeTzPattern,
87
93
  parser: (value) => luxon_1.DateTime.fromISO(value, options),
88
- }));
94
+ });
89
95
  }
90
96
  const dateTimeMillisPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
91
97
  function dateTimeMillis(options = { setZone: true }) {
92
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
93
- value,
94
- path,
95
- ctx,
98
+ return new LuxonValidator({
96
99
  type: 'DateTimeMillis',
97
100
  proto: luxon_2.DateTimeMillisLuxon,
98
101
  pattern: dateTimeMillisPattern,
99
102
  parser: (value) => luxon_1.DateTime.fromISO(value, options),
100
- }));
103
+ });
101
104
  }
102
105
  function dateTimeMillisUtc(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
103
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
104
- value,
105
- path,
106
- ctx,
106
+ return new LuxonValidator({
107
107
  type: 'DateTimeMillis',
108
108
  proto: luxon_2.DateTimeMillisUtcLuxon,
109
109
  pattern: dateTimeMillisPattern,
110
110
  parser: (value) => luxon_1.DateTime.fromISO(value, options),
111
- }));
111
+ });
112
112
  }
113
113
  function dateTimeFromISO(options = { setZone: true }) {
114
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
115
- value,
116
- path,
117
- ctx,
114
+ return new LuxonValidator({
118
115
  type: 'ISODateTime',
119
116
  pattern: /./,
120
117
  parser: (value) => luxon_1.DateTime.fromISO(value, options),
121
- }));
118
+ });
122
119
  }
123
120
  function dateTimeFromRFC2822(options = { setZone: true }) {
124
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
125
- value,
126
- path,
127
- ctx,
121
+ return new LuxonValidator({
128
122
  type: 'RFC2822DateTime',
129
123
  pattern: /./,
130
124
  parser: (value) => luxon_1.DateTime.fromRFC2822(value, options),
131
- }));
125
+ });
132
126
  }
133
127
  function dateTimeFromHTTP(options = { setZone: true }) {
134
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
135
- value,
136
- path,
137
- ctx,
128
+ return new LuxonValidator({
138
129
  type: 'HTTPDateTime',
139
130
  pattern: /./,
140
131
  parser: (value) => luxon_1.DateTime.fromHTTP(value, options),
141
- }));
132
+ });
142
133
  }
143
134
  function dateTimeFromSQL(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
144
- return v_validation_1.V.fn((value, path, ctx) => validateLuxon({
145
- value,
146
- path,
147
- ctx,
135
+ return new LuxonValidator({
148
136
  type: 'SQLDateTime',
149
137
  pattern: /./,
150
138
  parser: (value) => luxon_1.DateTime.fromSQL(value, options),
151
- }));
139
+ });
152
140
  }
153
141
  function validateLuxonNumber({ value, path, ctx, type, parser }) {
154
142
  return __awaiter(this, void 0, void 0, function* () {
@@ -213,6 +201,7 @@ exports.Vluxon = {
213
201
  // DateTime wrapper validators
214
202
  localDate,
215
203
  localTime,
204
+ localDateTime,
216
205
  dateTime,
217
206
  dateTimeUtc,
218
207
  dateTimeMillis,
package/dist/luxon.d.ts CHANGED
@@ -44,6 +44,21 @@ export declare class LocalTimeLuxon extends LuxonDateTime {
44
44
  wrap(fn: (dateTime: DateTime) => DateTime): LocalTimeLuxon;
45
45
  toJSON(): string;
46
46
  }
47
+ export declare class LocalDateTimeLuxon extends LuxonDateTime {
48
+ static readonly format = "yyyy-MM-dd'T'HH:mm:ss";
49
+ constructor(input: LuxonDateTimeInput);
50
+ static nowLocal(options?: DateTimeJSOptions): LocalDateTimeLuxon;
51
+ static nowUtc(): LocalDateTimeLuxon;
52
+ static fromISO(value: string, options?: DateTimeOptions): LocalDateTimeLuxon;
53
+ static fromFormat(value: string, format: string, options?: DateTimeOptions): LocalDateTimeLuxon;
54
+ static fromJSDate(date: Date, options?: {
55
+ zone?: string | Zone;
56
+ }): LocalDateTimeLuxon;
57
+ static fromMillis(millis: number, options?: DateTimeJSOptions): LocalDateTimeLuxon;
58
+ protected normalize(dateTime: DateTime): DateTime;
59
+ wrap(fn: (dateTime: DateTime) => DateTime): LocalDateTimeLuxon;
60
+ toJSON(): string;
61
+ }
47
62
  export declare class DateTimeLuxon extends LuxonDateTime {
48
63
  static readonly format = "yyyy-MM-dd'T'HH:mm:ss";
49
64
  static readonly formatTz: string;
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.DateTimeMillisUtcLuxon = exports.DateTimeMillisLuxon = exports.DateTimeUtcLuxon = exports.DateTimeLuxon = exports.LocalTimeLuxon = exports.LocalDateLuxon = exports.LuxonDateTime = void 0;
4
+ exports.DateTimeMillisUtcLuxon = exports.DateTimeMillisLuxon = exports.DateTimeUtcLuxon = exports.DateTimeLuxon = exports.LocalDateTimeLuxon = exports.LocalTimeLuxon = exports.LocalDateLuxon = exports.LuxonDateTime = void 0;
5
5
  const luxon_1 = require("luxon");
6
6
  class LuxonDateTime {
7
7
  constructor(input) {
@@ -113,6 +113,40 @@ class LocalTimeLuxon extends LuxonDateTime {
113
113
  }
114
114
  exports.LocalTimeLuxon = LocalTimeLuxon;
115
115
  LocalTimeLuxon.format = 'HH:mm:ss';
116
+ class LocalDateTimeLuxon extends LuxonDateTime {
117
+ constructor(input) {
118
+ super(input);
119
+ }
120
+ static nowLocal(options) {
121
+ return new LocalDateTimeLuxon(luxon_1.DateTime.local(options));
122
+ }
123
+ static nowUtc() {
124
+ return new LocalDateTimeLuxon(luxon_1.DateTime.utc());
125
+ }
126
+ static fromISO(value, options) {
127
+ return new LocalDateTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
128
+ }
129
+ static fromFormat(value, format, options) {
130
+ return new LocalDateTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
131
+ }
132
+ static fromJSDate(date, options) {
133
+ return new LocalDateTimeLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
134
+ }
135
+ static fromMillis(millis, options) {
136
+ return new LocalDateTimeLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
137
+ }
138
+ normalize(dateTime) {
139
+ return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second);
140
+ }
141
+ wrap(fn) {
142
+ return new LocalDateTimeLuxon(fn(this.dateTime));
143
+ }
144
+ toJSON() {
145
+ return this.dateTime.toFormat(LocalDateTimeLuxon.format);
146
+ }
147
+ }
148
+ exports.LocalDateTimeLuxon = LocalDateTimeLuxon;
149
+ LocalDateTimeLuxon.format = "yyyy-MM-dd'T'HH:mm:ss";
116
150
  class DateTimeLuxon extends LuxonDateTime {
117
151
  constructor(input) {
118
152
  super(input);
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
- var _a, _b;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  const luxon_1 = require("luxon");
5
- console.log(luxon_1.DateTime.fromMillis(luxon_1.DateTime.fromISO('2022-08-30T23:00:00Z').toMillis(), { zone: luxon_1.FixedOffsetZone.instance(180) }).toJSON());
6
- let o = { foo: 1 };
7
- console.log((_b = (_a = o.foo) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : 'not found');
4
+ const dt = luxon_1.DateTime.fromISO('2022-10-29T23:30:00').setZone(luxon_1.FixedOffsetZone.instance(-60), { keepLocalTime: true });
5
+ console.log(dt);
6
+ console.log(dt.setZone(luxon_1.FixedOffsetZone.utcInstance));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finnair/v-validation-luxon",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.1.0",
4
4
  "private": false,
5
5
  "description": "Luxon validators",
6
6
  "main": "dist/index.js",
@@ -25,12 +25,11 @@
25
25
  "build": "tsc -b ."
26
26
  },
27
27
  "dependencies": {
28
- "@finnair/path": "^3.0.0-alpha.2",
29
- "@finnair/v-validation": "^3.0.0-alpha.2",
30
- "luxon": "3.0.3"
28
+ "@finnair/path": "^3.1.0",
29
+ "@finnair/v-validation": "^3.1.0"
31
30
  },
32
- "devDependencies": {
33
- "@types/luxon": "3.0.1"
31
+ "peerDependencies": {
32
+ "luxon": "^3.0.0"
34
33
  },
35
- "gitHead": "d42bd7583bb684429e48ce8e5db3938cb95ffd5f"
34
+ "gitHead": "5182a63fa61cc1f5c8991e1482c5bbffe14798c3"
36
35
  }