@fabriktor/fx 0.0.80 → 0.0.81

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.
@@ -10,3 +10,5 @@ export declare function normalizeInputDate(v: InDate): InDate;
10
10
  export declare function zeroInputDate(): InDate;
11
11
  export declare function zeroDate(): SchemaDate;
12
12
  export declare function isZeroDate(v: LocalDateParts): boolean;
13
+ export declare function isZeroDateTime(value: string | null | undefined): boolean;
14
+ export declare function isZeroSchemaDate(value: SchemaDate | null | undefined): boolean;
@@ -3,7 +3,19 @@
3
3
  // Licensed under the Apache License, Version 2.0 (the "License"); you may
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- const zeroUTC = "0001-01-01T00:00:00Z";
6
+ const zeroDateParts = {
7
+ y: 1,
8
+ m: 1,
9
+ d: 1,
10
+ h: 0,
11
+ min: 0,
12
+ };
13
+ const zeroDatePrefix = [
14
+ String(zeroDateParts.y).padStart(4, "0"),
15
+ String(zeroDateParts.m).padStart(2, "0"),
16
+ String(zeroDateParts.d).padStart(2, "0"),
17
+ ].join("-");
18
+ const zeroUTC = `${zeroDatePrefix}T00:00:00Z`;
7
19
  const utcTimezone = "UTC";
8
20
  export function normalizeInputDate(v) {
9
21
  if (isZeroDate(v)) {
@@ -13,11 +25,7 @@ export function normalizeInputDate(v) {
13
25
  }
14
26
  export function zeroInputDate() {
15
27
  return {
16
- y: 1,
17
- m: 1,
18
- d: 1,
19
- h: 0,
20
- min: 0,
28
+ ...zeroDateParts,
21
29
  tz: utcTimezone,
22
30
  };
23
31
  }
@@ -28,9 +36,20 @@ export function zeroDate() {
28
36
  };
29
37
  }
30
38
  export function isZeroDate(v) {
31
- if (v.h !== 0 || v.min !== 0) {
39
+ if (v.h !== zeroDateParts.h || v.min !== zeroDateParts.min) {
32
40
  return false;
33
41
  }
34
42
  return ((v.y === 0 && v.m === 0 && v.d === 0) ||
35
- (v.y === 1 && v.m === 1 && v.d === 1));
43
+ (v.y === zeroDateParts.y &&
44
+ v.m === zeroDateParts.m &&
45
+ v.d === zeroDateParts.d));
46
+ }
47
+ export function isZeroDateTime(value) {
48
+ const timestamp = value?.trim() ?? "";
49
+ return timestamp === "" || timestamp.startsWith(zeroDatePrefix);
50
+ }
51
+ export function isZeroSchemaDate(value) {
52
+ return (value === null ||
53
+ value === undefined ||
54
+ (isZeroDate(value) && isZeroDateTime(value.utc)));
36
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.80",
3
+ "version": "0.0.81",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {