Files
superlist/apps/web/src/lib/dates.test.ts
Jose Selesan 4ff864a557
Some checks failed
CI / Verify (push) Has been cancelled
feat: show bought items in a collapsible section for the current day only
Bought items now move down to a 'Comprados hoy' collapsible section
(expanded by default) below the pending ones, and are only visible on
the local day they were bought. Items bought on previous days stay
completed in the database but are hidden from the list.
2026-10-16 11:08:42 -03:00

29 lines
970 B
TypeScript

import { describe, expect, it } from 'vitest'
import { isSameLocalDay } from './dates'
describe('isSameLocalDay', () => {
it('matches two moments of the same local day', () => {
const morning = new Date(2026, 9, 15, 8, 30)
const night = new Date(2026, 9, 15, 23, 59)
expect(isSameLocalDay(morning, night)).toBe(true)
})
it('does not match moments across local midnight', () => {
const justBefore = new Date(2026, 9, 15, 23, 59)
const justAfter = new Date(2026, 9, 16, 0, 1)
expect(isSameLocalDay(justBefore, justAfter)).toBe(false)
})
it('compares in the local timezone, not in UTC', () => {
// 23:30 local on Oct 15th is already Oct 16th in UTC for UTC-negative
// timezones, so a naive UTC comparison would report different days.
const localNight = new Date(2026, 9, 15, 23, 30)
const nextLocalMidnight = new Date(2026, 9, 16, 0, 0)
expect(isSameLocalDay(localNight, nextLocalMidnight)).toBe(false)
})
})