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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.1.0-alpha.7](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.6...v1.1.0-alpha.7) (2022-08-18)
7
+
8
+ **Note:** Version bump only for package @finnair/v-validation-luxon
9
+
10
+
11
+
12
+
13
+
6
14
  # [1.1.0-alpha.6](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.6) (2022-08-17)
7
15
 
8
16
 
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, DateTimeOptions } 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
- options: DateTimeOptions;
13
+ parser: (value: string) => DateTime;
14
14
  }
15
- export declare function validateLuxon({ value, path, ctx, type, proto, pattern, options }: ValidateLuxonParams): ValidationResult;
15
+ export declare function validateLuxon({ value, path, ctx, type, proto, pattern, parser }: ValidateLuxonParams): 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,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, options }) {
16
+ function validateLuxon({ value, path, ctx, type, proto, pattern, parser }) {
17
17
  if ((0, v_validation_1.isNullOrUndefined)(value)) {
18
18
  return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
19
19
  }
@@ -27,7 +27,7 @@ function validateLuxon({ value, path, ctx, type, proto, pattern, options }) {
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, options);
30
+ const dateTime = parser(value);
31
31
  if (dateTime.isValid) {
32
32
  return ctx.success(new proto(dateTime));
33
33
  }
@@ -46,7 +46,7 @@ function localDateValidator(value, path, ctx) {
46
46
  type: 'Date',
47
47
  proto: luxon_2.LocalDateLuxon,
48
48
  pattern: datePattern,
49
- options: { zone: luxon_1.FixedOffsetZone.utcInstance },
49
+ parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
50
50
  });
51
51
  });
52
52
  }
@@ -60,7 +60,7 @@ function localTimeValidator(value, path, ctx) {
60
60
  type: 'Time',
61
61
  proto: luxon_2.LocalTimeLuxon,
62
62
  pattern: timePattern,
63
- options: { zone: luxon_1.FixedOffsetZone.utcInstance },
63
+ parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
64
64
  });
65
65
  });
66
66
  }
@@ -74,7 +74,7 @@ function dateTimeValidator(value, path, ctx) {
74
74
  type: 'DateTime',
75
75
  proto: luxon_2.DateTimeLuxon,
76
76
  pattern: dateTimePattern,
77
- options: { setZone: true },
77
+ parser: (value) => luxon_1.DateTime.fromISO(value, { setZone: true }),
78
78
  });
79
79
  });
80
80
  }
@@ -87,7 +87,7 @@ function dateTimeUtcValidator(value, path, ctx) {
87
87
  type: 'DateTime',
88
88
  proto: luxon_2.DateTimeUtcLuxon,
89
89
  pattern: dateTimePattern,
90
- options: { zone: luxon_1.FixedOffsetZone.utcInstance },
90
+ parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
91
91
  });
92
92
  });
93
93
  }
@@ -101,7 +101,7 @@ function dateTimeMillisValidator(value, path, ctx) {
101
101
  type: 'DateTimeMillis',
102
102
  proto: luxon_2.DateTimeMillisLuxon,
103
103
  pattern: dateTimeMillisPattern,
104
- options: { setZone: true },
104
+ parser: (value) => luxon_1.DateTime.fromISO(value, { setZone: true }),
105
105
  });
106
106
  });
107
107
  }
@@ -114,7 +114,7 @@ function dateTimeMillisUtcValidator(value, path, ctx) {
114
114
  type: 'DateTimeMillis',
115
115
  proto: luxon_2.DateTimeMillisUtcLuxon,
116
116
  pattern: dateTimeMillisPattern,
117
- options: { zone: luxon_1.FixedOffsetZone.utcInstance },
117
+ parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
118
118
  });
119
119
  });
120
120
  }
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) {
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const luxon_1 = require("luxon");
4
- const d = luxon_1.DateTime.fromISO('2016-05-25T09:08:34.123');
5
- console.log(d === d.toUTC());
4
+ console.log(luxon_1.DateTime.fromISO('2022-02-27').set({ day: 31 }).day);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finnair/v-validation-luxon",
3
- "version": "1.1.0-alpha.6",
3
+ "version": "1.1.0-alpha.7",
4
4
  "private": false,
5
5
  "description": "Luxon validators",
6
6
  "main": "dist/index.js",
@@ -32,5 +32,5 @@
32
32
  "devDependencies": {
33
33
  "@types/luxon": "3.0.0"
34
34
  },
35
- "gitHead": "cbca3585a6777f34cd135c6c22be566aea34e69b"
35
+ "gitHead": "b270437f1a403fbb012297653f05d7d6d732fa76"
36
36
  }