@aspan-corporation/ac-shared 1.2.31 → 1.2.32

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.
@@ -23,9 +23,13 @@ export declare const DIARY_PREVIEW_LENGTH = 160;
23
23
  export declare const MAX_TEXT_TOKENS = 400;
24
24
  /**
25
25
  * Compute the diary object key for a date.
26
- * new Date("2026-06-15") "diary/2026/06/20260615.md"
27
- * Accepts a Date or an ISO/`YYYY-MM-DD` string. Uses UTC parts so the key is
28
- * stable regardless of the runtime timezone.
26
+ * diaryKey(new Date()) today's key in the caller's LOCAL timezone
27
+ * diaryKey("2026-06-15") "diary/2026/06/20260615.md" (literal Y-M-D)
28
+ *
29
+ * A `Date` is read with LOCAL components so "today" is the caller's wall-clock
30
+ * day (not the UTC day, which is a day ahead for users west of UTC in the
31
+ * evening). A `YYYY-MM-DD` string (e.g. from <input type="date">) is taken
32
+ * literally so the date round-trips exactly with no timezone shift.
29
33
  */
30
34
  export declare const diaryKey: (date: Date | string) => string;
31
35
  /** True when an id/key is a diary entry object. */
@@ -24,19 +24,42 @@ export const MAX_TEXT_TOKENS = 400;
24
24
  const pad2 = (n) => String(n).padStart(2, "0");
25
25
  /**
26
26
  * Compute the diary object key for a date.
27
- * new Date("2026-06-15") "diary/2026/06/20260615.md"
28
- * Accepts a Date or an ISO/`YYYY-MM-DD` string. Uses UTC parts so the key is
29
- * stable regardless of the runtime timezone.
27
+ * diaryKey(new Date()) today's key in the caller's LOCAL timezone
28
+ * diaryKey("2026-06-15") "diary/2026/06/20260615.md" (literal Y-M-D)
29
+ *
30
+ * A `Date` is read with LOCAL components so "today" is the caller's wall-clock
31
+ * day (not the UTC day, which is a day ahead for users west of UTC in the
32
+ * evening). A `YYYY-MM-DD` string (e.g. from <input type="date">) is taken
33
+ * literally so the date round-trips exactly with no timezone shift.
30
34
  */
31
35
  export const diaryKey = (date) => {
32
- const d = typeof date === "string" ? new Date(date) : date;
33
- if (isNaN(d.getTime())) {
34
- throw new Error(`diaryKey: invalid date "${String(date)}"`);
36
+ let y;
37
+ let m;
38
+ let day;
39
+ if (typeof date === "string") {
40
+ const lit = /^(\d{4})-(\d{2})-(\d{2})/.exec(date);
41
+ if (lit) {
42
+ y = Number(lit[1]);
43
+ m = Number(lit[2]);
44
+ day = Number(lit[3]);
45
+ }
46
+ else {
47
+ const d = new Date(date);
48
+ if (isNaN(d.getTime()))
49
+ throw new Error(`diaryKey: invalid date "${date}"`);
50
+ y = d.getFullYear();
51
+ m = d.getMonth() + 1;
52
+ day = d.getDate();
53
+ }
54
+ }
55
+ else {
56
+ if (isNaN(date.getTime()))
57
+ throw new Error("diaryKey: invalid Date");
58
+ y = date.getFullYear();
59
+ m = date.getMonth() + 1;
60
+ day = date.getDate();
35
61
  }
36
- const y = d.getUTCFullYear();
37
- const m = pad2(d.getUTCMonth() + 1);
38
- const day = pad2(d.getUTCDate());
39
- return `${DIARY_PREFIX}${y}/${m}/${y}${m}${day}.md`;
62
+ return `${DIARY_PREFIX}${y}/${pad2(m)}/${y}${pad2(m)}${pad2(day)}.md`;
40
63
  };
41
64
  /** True when an id/key is a diary entry object. */
42
65
  export const isDiaryKey = (key) => key.startsWith(DIARY_PREFIX) && key.endsWith(".md");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspan-corporation/ac-shared",
3
- "version": "1.2.31",
3
+ "version": "1.2.32",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "exports": {