web/src/utils/dates-n-stuff.test.ts

32 lines · 969 bytes

 1import { describe, it, expect } from 'vitest';
 2import { formatDate, timestampToDate } from './dates-n-stuff';
 3
 4describe('formatDate', () => {
 5  it('formats an ISO date string to en-GB short format', () => {
 6    const result = formatDate('2024-01-15');
 7    expect(result).toBe('15 Jan 24');
 8  });
 9
10  it('formats a different date correctly', () => {
11    const result = formatDate('2023-12-25');
12    expect(result).toBe('25 Dec 23');
13  });
14
15  it('handles full ISO datetime string', () => {
16    const result = formatDate('2024-06-01T12:00:00Z');
17    expect(result).toBe('01 Jun 24');
18  });
19});
20
21describe('timestampToDate', () => {
22  it('converts a Unix timestamp (ms) to en-GB short format', () => {
23    // 2024-01-15T00:00:00Z = 1705276800000
24    const result = timestampToDate(1705276800000);
25    expect(result).toBe('15 Jan 24');
26  });
27
28  it('converts epoch 0 to 01 Jan 70', () => {
29    const result = timestampToDate(0);
30    expect(result).toBe('01 Jan 70');
31  });
32});