refactor: move shared utilities to lib/shared/ sub-packages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
50
frontend/src/lib/shared/utils/date-buckets.spec.ts
Normal file
50
frontend/src/lib/shared/utils/date-buckets.spec.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { bucketByDay } from './date-buckets';
|
||||
|
||||
function date(iso: string): Date {
|
||||
return new Date(iso);
|
||||
}
|
||||
|
||||
describe('bucketByDay', () => {
|
||||
// Wednesday 2026-04-22 at 12:00 Berlin. Week start (Mon) = 2026-04-20.
|
||||
const now = date('2026-04-22T12:00:00+02:00');
|
||||
|
||||
it('returns "today" for a time earlier today', () => {
|
||||
expect(bucketByDay(date('2026-04-22T06:00:00+02:00'), now, 'de-DE')).toBe('today');
|
||||
});
|
||||
|
||||
it('returns "today" at exact midnight start of today', () => {
|
||||
expect(bucketByDay(date('2026-04-22T00:00:00+02:00'), now, 'de-DE')).toBe('today');
|
||||
});
|
||||
|
||||
it('returns "yesterday" for any time on the previous day', () => {
|
||||
expect(bucketByDay(date('2026-04-21T23:59:59+02:00'), now, 'de-DE')).toBe('yesterday');
|
||||
expect(bucketByDay(date('2026-04-21T00:00:00+02:00'), now, 'de-DE')).toBe('yesterday');
|
||||
});
|
||||
|
||||
it('returns "thisWeek" for the Monday that starts this week (Monday-anchored, de-DE)', () => {
|
||||
expect(bucketByDay(date('2026-04-20T10:00:00+02:00'), now, 'de-DE')).toBe('thisWeek');
|
||||
});
|
||||
|
||||
it('returns "older" for anything before the start of this week (de-DE)', () => {
|
||||
expect(bucketByDay(date('2026-04-19T23:00:00+02:00'), now, 'de-DE')).toBe('older');
|
||||
expect(bucketByDay(date('2026-04-13T10:00:00+02:00'), now, 'de-DE')).toBe('older');
|
||||
});
|
||||
|
||||
it('uses Sunday-start week for en-US', () => {
|
||||
const sundayRef = date('2026-04-19T12:00:00+02:00');
|
||||
expect(bucketByDay(date('2026-04-19T06:00:00+02:00'), sundayRef, 'en-US')).toBe('today');
|
||||
expect(
|
||||
bucketByDay(date('2026-04-13T10:00:00+02:00'), date('2026-04-18T12:00:00+02:00'), 'en-US')
|
||||
).toBe('thisWeek');
|
||||
expect(
|
||||
bucketByDay(date('2026-04-11T10:00:00+02:00'), date('2026-04-18T12:00:00+02:00'), 'en-US')
|
||||
).toBe('older');
|
||||
});
|
||||
|
||||
it('handles DST spring-forward correctly (Europe/Berlin 2026-03-29)', () => {
|
||||
const justAfterDst = date('2026-03-29T03:15:00+02:00');
|
||||
const sameDay = date('2026-03-29T10:00:00+02:00');
|
||||
expect(bucketByDay(justAfterDst, sameDay, 'de-DE')).toBe('today');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user