Skip to content

Commit 5710476

Browse files
author
ComputelessComputer
committed
Fix date parsing to use local time
1 parent 4a7686b commit 5710476

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/pages/journals/[id].astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ const { Content } = await render(journal);
1717
1818
// Parse date from filename (2026_01_02 -> 2026-01-02)
1919
const dateStr = journal.id.replace(/_/g, "-");
20-
const journalDate = new Date(dateStr);
20+
// Parse as local date, not UTC (ISO strings are parsed as UTC by default)
21+
const [year, month, day] = dateStr.split("-").map(Number);
22+
const journalDate = new Date(year, month - 1, day, 0, 0, 0, 0);
2123
const today = new Date();
2224
today.setHours(0, 0, 0, 0);
23-
journalDate.setHours(0, 0, 0, 0);
2425
2526
const diffTime = today.getTime() - journalDate.getTime();
2627
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));

src/pages/journals/index.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ const today = new Date();
1010
today.setHours(0, 0, 0, 0);
1111
1212
function getRelativeDate(dateStr: string): string {
13-
const journalDate = new Date(dateStr);
14-
journalDate.setHours(0, 0, 0, 0);
13+
// Parse as local date, not UTC (ISO strings are parsed as UTC by default)
14+
const [year, month, day] = dateStr.split("-").map(Number);
15+
const journalDate = new Date(year, month - 1, day, 0, 0, 0, 0);
1516
1617
const diffTime = today.getTime() - journalDate.getTime();
1718
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));

0 commit comments

Comments
 (0)