M9 S3 (frontend): consolidate local-date helpers into notes/datetime.ts
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:
@@ -2,6 +2,7 @@
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { api } from "../api/client";
|
||||
import { type Note } from "../stores/notes";
|
||||
import { addLocalDays, parseLocalDate } from "../notes/datetime";
|
||||
import { useNoteList } from "../composables/useNoteList";
|
||||
import { useNoteEditor } from "../composables/useNoteEditor";
|
||||
import AsyncState from "../components/AsyncState.vue";
|
||||
@@ -18,23 +19,13 @@ const fromDate = ref("");
|
||||
const toDate = ref("");
|
||||
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 {
|
||||
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());
|
||||
const to = localDate(toDate.value);
|
||||
if (to) {
|
||||
// Half-open upper bound: start of the day AFTER `to`, so the whole `to` day is included.
|
||||
const end = new Date(to.getFullYear(), to.getMonth(), to.getDate() + 1);
|
||||
params.set("created_before", end.toISOString());
|
||||
}
|
||||
const to = parseLocalDate(toDate.value);
|
||||
// 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());
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user