Lines 1-37javascript
1// streak-daykey-lib — calendar-day and streak math primitives.
3// This is the dependency-free helper behind `streak-daykey-lib`.
4// It is deliberately NOT referenced from the app's own source. The main package
5// (streak-daykey-lib) imports it; the app only ever imports the main package.
7// This entry is PURE and browser-safe: it uses only Intl (no node:fs, no other
8// node:* built-ins), so the browser-safe core of streak-daykey-lib can depend
9// on it. The Node-only on-disk store lives in the separate `streak-daykey-lib/store`
10// subpath, which the app never touches directly.
11const pad = (n) => String(n).padStart(2, '0');
14 * Calendar-day key ("YYYY-MM-DD") for a date, evaluated in `timeZone`.
16export function dayKey(date, timeZone = 'UTC') {
17 const d = date instanceof Date ? date : new Date(date);
18 const dtf = new Intl.DateTimeFormat('en-CA', {
19 timeZone,
HighBase64 Obscured Url
Source decodes a Base64-obscured HTTP endpoint at runtime.
index.mjsView on unpkg · L17 27/** Shift a day key by `n` whole days (n may be negative). */
28export function addDays(key, n) {
29 const [y, m, d] = key.split('-').map(Number);
30 const dt = new Date(Date.UTC(y, m - 1, d));
31 dt.setUTCDate(dt.getUTCDate() + n);
32 return `${dt.getUTCFullYear()}-${pad(dt.getUTCMonth() + 1)}-${pad(dt.getUTCDate())}`;
35/** Whole-day difference aKey - bKey. */
36export function dayDiff(aKey, bKey) {