M9 S3 (frontend): consolidate local-date helpers into notes/datetime.ts
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 6s
CI & Build / Python tests (push) Successful in 11s
CI & Build / Build & push image (push) Successful in 30s

The created-date range facets built local-day bounds by hand in two places
(FilterBar's onTo/toInput, TimelineView's buildQuery) — parse a
"YYYY-MM-DD", shift a day for the half-open upper bound, format back.

- datetime.ts: parseLocalDate() / addLocalDays() (non-mutating) / formatLocalDay().
- TimelineView: drops its inline localDate() + the +1-day Date math.
- FilterBar: drops its inline isoDay() + the setDate(±1) mutations.

Behavior-preserving and deliberately NOT unifying output: Timeline still
emits UTC (.toISOString()) bounds, FilterBar still emits naive-local
"…T00:00:00" strings — only the shared primitives are extracted. (The
naive-vs-UTC divergence is a separate backend-datetime-semantics question,
flagged for later, not silently changed.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm
This commit is contained in:
2026-07-23 21:40:13 -04:00
co-authored by Claude Opus 4.8
parent 590d3ff2f6
commit e1cf63e875
3 changed files with 35 additions and 25 deletions
+7 -11
View File
@@ -6,6 +6,7 @@ import { useSavedFiltersStore } from "../stores/savedFilters";
import { useUiStore } from "../stores/ui"; import { useUiStore } from "../stores/ui";
import type { NoteFacets } from "../stores/notes"; import type { NoteFacets } from "../stores/notes";
import { facetCount, facetsFromQuery, facetsToQuery } from "../notes/facets"; import { facetCount, facetsFromQuery, facetsToQuery } from "../notes/facets";
import { addLocalDays, formatLocalDay, parseLocalDate } from "../notes/datetime";
import { NOTE_COLOR_KEYS, NOTE_COLOR_LABELS, NOTE_SWATCH_CLASSES, type NoteColor } from "../notes/colors"; import { NOTE_COLOR_KEYS, NOTE_COLOR_LABELS, NOTE_SWATCH_CLASSES, type NoteColor } from "../notes/colors";
import Icon from "./Icon.vue"; import Icon from "./Icon.vue";
@@ -56,30 +57,25 @@ function onQ(e: Event) {
qTimer = setTimeout(() => patch({ q: v.trim() || undefined }), 300); qTimer = setTimeout(() => patch({ q: v.trim() || undefined }), 300);
} }
function isoDay(d: Date): string {
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
}
function onFrom(e: Event) { function onFrom(e: Event) {
const v = (e.target as HTMLInputElement).value; const v = (e.target as HTMLInputElement).value;
patch({ created_after: v ? `${v}T00:00:00` : undefined }); patch({ created_after: v ? `${v}T00:00:00` : undefined });
} }
function onTo(e: Event) { function onTo(e: Event) {
const v = (e.target as HTMLInputElement).value; const v = (e.target as HTMLInputElement).value;
if (!v) { const d = v ? parseLocalDate(v) : null;
if (!d) {
patch({ created_before: undefined }); patch({ created_before: undefined });
return; return;
} }
// Half-open upper bound: the start of the day AFTER the chosen date (so it's inclusive). // Half-open upper bound: the start of the day AFTER the chosen date (so it's inclusive).
const d = new Date(`${v}T00:00:00`); patch({ created_before: `${formatLocalDay(addLocalDays(d, 1))}T00:00:00` });
d.setDate(d.getDate() + 1);
patch({ created_before: `${isoDay(d)}T00:00:00` });
} }
const fromInput = computed(() => (facets.value.created_after ?? "").slice(0, 10)); const fromInput = computed(() => (facets.value.created_after ?? "").slice(0, 10));
const toInput = computed(() => { const toInput = computed(() => {
if (!facets.value.created_before) return ""; // Reverse the half-open bound (day-after) back to the chosen end day for the input.
const d = new Date(facets.value.created_before); const d = facets.value.created_before ? parseLocalDate(facets.value.created_before.slice(0, 10)) : null;
d.setDate(d.getDate() - 1); return d ? formatLocalDay(addLocalDays(d, -1)) : "";
return isoDay(d);
}); });
async function saveView() { async function saveView() {
+23
View File
@@ -26,3 +26,26 @@ export function formatReminder(iso: string | null): string {
export function isOverdue(iso: string | null): boolean { export function isOverdue(iso: string | null): boolean {
return !!iso && new Date(iso).getTime() < Date.now(); return !!iso && new Date(iso).getTime() < Date.now();
} }
// --- Local calendar-date helpers (the created-date range facets work in the viewer's
// LOCAL day; the board's FilterBar and the Timeline view both build day bounds). ---
// Parse an <input type="date"> value ("YYYY-MM-DD") as a LOCAL calendar date (midnight
// local), or null if it isn't a valid YYYY-MM-DD.
export function parseLocalDate(value: string): Date | null {
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
if (!m) return null;
return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
}
// A new local Date shifted by whole days — e.g. +1 for the half-open upper bound that
// includes the whole end day, -1 to reverse it for display. Non-mutating.
export function addLocalDays(d: Date, days: number): Date {
return new Date(d.getFullYear(), d.getMonth(), d.getDate() + days);
}
// Format a local Date as "YYYY-MM-DD" (the shape an <input type="date"> reads).
export function formatLocalDay(d: Date): string {
const pad = (n: number) => String(n).padStart(2, "0");
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
}
+5 -14
View File
@@ -2,6 +2,7 @@
import { computed, onMounted, ref, watch } from "vue"; import { computed, onMounted, ref, watch } from "vue";
import { api } from "../api/client"; import { api } from "../api/client";
import { type Note } from "../stores/notes"; import { type Note } from "../stores/notes";
import { addLocalDays, parseLocalDate } from "../notes/datetime";
import { useNoteList } from "../composables/useNoteList"; import { useNoteList } from "../composables/useNoteList";
import { useNoteEditor } from "../composables/useNoteEditor"; import { useNoteEditor } from "../composables/useNoteEditor";
import AsyncState from "../components/AsyncState.vue"; import AsyncState from "../components/AsyncState.vue";
@@ -18,23 +19,13 @@ const fromDate = ref("");
const toDate = ref(""); const toDate = ref("");
const hasRange = computed(() => !!fromDate.value || !!toDate.value); const hasRange = computed(() => !!fromDate.value || !!toDate.value);
// Parse an <input type="date"> value ("YYYY-MM-DD") as a LOCAL calendar date.
function localDate(value: string): Date | null {
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
if (!m) return null;
return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
}
function buildQuery(): string { function buildQuery(): string {
const params = new URLSearchParams({ filter: "active", sort: "created" }); const params = new URLSearchParams({ filter: "active", sort: "created" });
const from = localDate(fromDate.value); const from = parseLocalDate(fromDate.value);
if (from) params.set("created_after", from.toISOString()); if (from) params.set("created_after", from.toISOString());
const to = localDate(toDate.value); const to = parseLocalDate(toDate.value);
if (to) { // Half-open upper bound: start of the day AFTER `to`, so the whole `to` day is included.
// Half-open upper bound: start of the day AFTER `to`, so the whole `to` day is included. if (to) params.set("created_before", addLocalDays(to, 1).toISOString());
const end = new Date(to.getFullYear(), to.getMonth(), to.getDate() + 1);
params.set("created_before", end.toISOString());
}
return params.toString(); return params.toString();
} }