@stll/template-conditions 0.5.0 → 0.5.1

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.
Files changed (2) hide show
  1. package/dist/index.js +9 -8
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { conditionHasFormula, conditionNodeSchema, conditionSchema, emptyCondition, evaluateCondition as evaluateCondition$1 } from "@stll/conditions";
2
- import { panic } from "better-result";
2
+ import { Result, panic } from "better-result";
3
+ import { Temporal } from "temporal-polyfill/full";
3
4
  //#region src/path.ts
4
5
  /**
5
6
  * Dotted-path resolution against a data record. Extracted from index.ts so both
@@ -504,15 +505,11 @@ const getDateFormatter = (locale, style) => {
504
505
  };
505
506
  /**
506
507
  * Parse a strict YYYY-MM-DD calendar date; null when malformed or not a real
507
- * date. UTC-anchored so the rendered day never shifts with the timezone.
508
- * `Date` rolls out-of-range components over (2028-02-30 → March 1), so the
509
- * round-trip comparison catches non-existent dates.
508
+ * date.
510
509
  */
511
510
  const parseIsoDate = (value) => {
512
511
  if (!ISO_DATE_PATTERN.test(value)) return null;
513
- const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
514
- if (Number.isNaN(date.getTime()) || !date.toISOString().startsWith(value)) return null;
515
- return date;
512
+ return Result.try(() => Temporal.PlainDate.from(value)).unwrapOr(null);
516
513
  };
517
514
  /**
518
515
  * Format an ISO date (YYYY-MM-DD) per the field's locale + style via
@@ -525,7 +522,11 @@ const formatDate = (value, dateFormat) => {
525
522
  const date = parseIsoDate(value);
526
523
  if (date === null) return null;
527
524
  if (dateFormat.style === "iso") return value;
528
- return getDateFormatter(dateFormat.locale, dateFormat.style).format(date);
525
+ const epochMilliseconds = date.toZonedDateTime({
526
+ plainTime: Temporal.PlainTime.from("00:00"),
527
+ timeZone: "UTC"
528
+ }).epochMilliseconds;
529
+ return getDateFormatter(dateFormat.locale, dateFormat.style).format(epochMilliseconds);
529
530
  };
530
531
  /**
531
532
  * THE deterministic field-value dispatcher: returns the string the fill engine
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/template-conditions",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "A document-template marker and condition engine: {{...}} marker grammar, parse, compute, serialize, field values.",
5
5
  "keywords": [
6
6
  "condition",
@@ -50,7 +50,8 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@stll/conditions": "^0.3.1",
53
- "better-result": "3.0.1"
53
+ "better-result": "3.0.1",
54
+ "temporal-polyfill": "1.0.4"
54
55
  },
55
56
  "devDependencies": {
56
57
  "@stll/property-testing": "0.0.0",