habits-free.openapps.xyz

Source

This app’s code and revision history are public. Download a copy or explore the files below.

Public
The app’s code and revision history are public.
Owned app · rev bc888334fc51
Run it yourself
Take the whole tree and run it on your own machine. The download needs no account. Cloning needs a sign-in.
Download .zip
bounded clone e8a688fd21351d04b05468df
A copy you download is not bounded. The guarantees this app runs under - declared egress, proven invariants, writes that fail closed - live in the runtime serving this page, not in the files. What you get is auditable source you can read and run, with no runtime guarantees attached.
← All files
src/lib/dates.ts
// Days are the person's local calendar dates, kept as "YYYY-MM-DD". For arithmetic they become day
// numbers (days since 1970-01-01), which never drift with time zones or daylight saving.
const DAY_MS = 86400000;

/** The local date as YYYY-MM-DD. */
export function dayKey(d = new Date()): string {
  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
}

export function dayNum(key: string): number {
  const [y, m, d] = key.split("-").map(Number);
  return Math.round(Date.UTC(y, m - 1, d) / DAY_MS);
}

export function keyOf(n: number): string {
  return new Date(n * DAY_MS).toISOString().slice(0, 10);
}

export const today = () => dayNum(dayKey());

/** 0 = Sunday ... 6 = Saturday. */
export const weekday = (n: number) => (((n + 4) % 7) + 7) % 7;

/** The first day of the week holding day n. */
export const weekOf = (n: number, startsOn: 0 | 1) => n - ((weekday(n) - startsOn + 7) % 7);

export const isDayKey = (s: string) => /^\d{4}-\d{2}-\d{2}$/.test(s) && keyOf(dayNum(s)) === s;

/** A day number shown in the person's language. */
export function fmt(n: number, opts: Intl.DateTimeFormatOptions = { month: "short", day: "numeric" }): string {
  return new Date(n * DAY_MS).toLocaleDateString(undefined, { ...opts, timeZone: "UTC" });
}

export const WEEKDAY_SHORT = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
export const WEEKDAY_LONG = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

Change history

Point OpenApps links to openapps.free
bc888334fc · 18 hours ago
Bind agent address in policy
1f744a2b83 · 19 hours ago
Use OpenApp service URLs and add contribution strip
a9bb601ee0 · 19 hours ago
Bounded source sync
5646afc3a0 · 1 day ago
Bounded source sync
f1b1bac8d6 · 1 day ago
Bounded source sync
b1e14b41b0 · 1 day ago