date-vir 0.2.1 → 0.2.3

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.
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.combineDateParts = void 0;
4
+ const object_shape_tester_1 = require("object-shape-tester");
4
5
  const full_date_shape_1 = require("./full-date-shape");
5
6
  function combineDateParts(maybeDateParts) {
6
- const timePart = maybeDateParts.time
7
+ const timePart = (0, object_shape_tester_1.isValidShape)(maybeDateParts.time, full_date_shape_1.timePartShape, {
8
+ allowExtraKeys: true,
9
+ })
7
10
  ? {
8
11
  hour: maybeDateParts.time.hour,
9
12
  minute: maybeDateParts.time.minute,
@@ -12,7 +15,9 @@ function combineDateParts(maybeDateParts) {
12
15
  timezone: maybeDateParts.time.timezone,
13
16
  }
14
17
  : undefined;
15
- const datePart = maybeDateParts.date
18
+ const datePart = (0, object_shape_tester_1.isValidShape)(maybeDateParts.date, full_date_shape_1.datePartShape, {
19
+ allowExtraKeys: true,
20
+ })
16
21
  ? {
17
22
  year: maybeDateParts.date.year,
18
23
  month: maybeDateParts.date.month,
@@ -54,9 +54,9 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
54
54
  throw new Error(`Tried to create date string but no day was provided.`);
55
55
  }
56
56
  const dateParts = [
57
- fullDate.year,
58
- String(fullDate.month).padStart(2, '0'),
59
- String(fullDate.day).padStart(2, '0'),
57
+ String(Math.abs(fullDate.year)).padStart(4, '0'),
58
+ String(Math.abs(fullDate.month)).padStart(2, '0'),
59
+ String(Math.abs(fullDate.day)).padStart(2, '0'),
60
60
  ];
61
61
  return dateParts.join('-');
62
62
  }
@@ -71,9 +71,9 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
71
71
  throw new Error(`Tried to create time string but no minutes were provided.`);
72
72
  }
73
73
  const timeParts = [
74
- String(fullDate.hour).padStart(2, '0'),
75
- String(fullDate.minute).padStart(2, '0'),
76
- includeSeconds ? String(fullDate.second).padStart(2, '0') : undefined,
74
+ String(Math.abs(fullDate.hour)).padStart(2, '0'),
75
+ String(Math.abs(fullDate.minute)).padStart(2, '0'),
76
+ includeSeconds ? String(Math.abs(fullDate.second ?? 0)).padStart(2, '0') : undefined,
77
77
  ].filter((entry) => entry != undefined);
78
78
  return timeParts.join(':');
79
79
  }
@@ -1,9 +1,9 @@
1
1
  import { DatePart, FullDate, FullDatePartEnum, TimePart } from './full-date-shape';
2
2
  type MaybeDateParts = Partial<{
3
- [FullDatePartEnum.Date]: DatePart | undefined;
4
- [FullDatePartEnum.Time]: TimePart | undefined;
3
+ [FullDatePartEnum.Date]: DatePart | undefined | Partial<FullDate>;
4
+ [FullDatePartEnum.Time]: TimePart | undefined | Partial<FullDate>;
5
5
  }>;
6
- export type MaybeDatePart = FullDate | DatePart | TimePart | undefined;
6
+ export type MaybeDatePart = FullDate | Partial<FullDate> | DatePart | TimePart | undefined;
7
7
  /**
8
8
  * Combine two parts of a FullDate objects into a filled-in FullDate. Note that the timezones must
9
9
  * match for both inputs. If two complete FullDate objects are passed in, only the respective parts
@@ -23,14 +23,14 @@ export declare function combineDateParts(maybeDateParts: {
23
23
  }): DatePart;
24
24
  export declare function combineDateParts(maybeDateParts: {
25
25
  [FullDatePartEnum.Date]: DatePart;
26
- [FullDatePartEnum.Time]?: TimePart | undefined;
26
+ [FullDatePartEnum.Time]?: TimePart | undefined | Partial<FullDate>;
27
27
  }): FullDate | DatePart;
28
28
  export declare function combineDateParts(maybeDateParts: {
29
29
  [FullDatePartEnum.Date]?: undefined;
30
30
  [FullDatePartEnum.Time]: TimePart;
31
31
  }): TimePart;
32
32
  export declare function combineDateParts(maybeDateParts: {
33
- [FullDatePartEnum.Date]?: DatePart | undefined;
33
+ [FullDatePartEnum.Date]?: DatePart | undefined | Partial<FullDate>;
34
34
  [FullDatePartEnum.Time]: TimePart;
35
35
  }): FullDate | TimePart;
36
36
  export declare function combineDateParts(maybeDateParts: MaybeDateParts): MaybeDatePart;
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.combineDateParts = void 0;
4
+ const object_shape_tester_1 = require("object-shape-tester");
4
5
  const full_date_shape_1 = require("./full-date-shape");
5
6
  function combineDateParts(maybeDateParts) {
6
- const timePart = maybeDateParts.time
7
+ const timePart = (0, object_shape_tester_1.isValidShape)(maybeDateParts.time, full_date_shape_1.timePartShape, {
8
+ allowExtraKeys: true,
9
+ })
7
10
  ? {
8
11
  hour: maybeDateParts.time.hour,
9
12
  minute: maybeDateParts.time.minute,
@@ -12,7 +15,9 @@ function combineDateParts(maybeDateParts) {
12
15
  timezone: maybeDateParts.time.timezone,
13
16
  }
14
17
  : undefined;
15
- const datePart = maybeDateParts.date
18
+ const datePart = (0, object_shape_tester_1.isValidShape)(maybeDateParts.date, full_date_shape_1.datePartShape, {
19
+ allowExtraKeys: true,
20
+ })
16
21
  ? {
17
22
  year: maybeDateParts.date.year,
18
23
  month: maybeDateParts.date.month,
@@ -54,9 +54,9 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
54
54
  throw new Error(`Tried to create date string but no day was provided.`);
55
55
  }
56
56
  const dateParts = [
57
- fullDate.year,
58
- String(fullDate.month).padStart(2, '0'),
59
- String(fullDate.day).padStart(2, '0'),
57
+ String(Math.abs(fullDate.year)).padStart(4, '0'),
58
+ String(Math.abs(fullDate.month)).padStart(2, '0'),
59
+ String(Math.abs(fullDate.day)).padStart(2, '0'),
60
60
  ];
61
61
  return dateParts.join('-');
62
62
  }
@@ -71,9 +71,9 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
71
71
  throw new Error(`Tried to create time string but no minutes were provided.`);
72
72
  }
73
73
  const timeParts = [
74
- String(fullDate.hour).padStart(2, '0'),
75
- String(fullDate.minute).padStart(2, '0'),
76
- includeSeconds ? String(fullDate.second).padStart(2, '0') : undefined,
74
+ String(Math.abs(fullDate.hour)).padStart(2, '0'),
75
+ String(Math.abs(fullDate.minute)).padStart(2, '0'),
76
+ includeSeconds ? String(Math.abs(fullDate.second ?? 0)).padStart(2, '0') : undefined,
77
77
  ].filter((entry) => entry != undefined);
78
78
  return timeParts.join(':');
79
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-vir",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Easy and explicit dates and times",
5
5
  "keywords": [
6
6
  "date",
@@ -42,7 +42,7 @@
42
42
  "@augment-vir/common": "^14.2.2",
43
43
  "@types/luxon": "^3.3.0",
44
44
  "luxon": "^3.3.0",
45
- "object-shape-tester": "^0.2.7",
45
+ "object-shape-tester": "^0.3.0",
46
46
  "type-fest": "^3.11.1"
47
47
  },
48
48
  "devDependencies": {
@@ -56,7 +56,7 @@
56
56
  "@web/test-runner-playwright": "^0.10.0",
57
57
  "@web/test-runner-visual-regression": "^0.8.0",
58
58
  "cspell": "^6.31.1",
59
- "element-vir": "^13.0.3",
59
+ "element-vir": "^13.0.4",
60
60
  "esbuild": "^0.17.19",
61
61
  "istanbul-smart-text-reporter": "^1.1.2",
62
62
  "markdown-code-example-inserter": "^0.3.1",