Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion workers/main/src/common/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ vi.mock('../configs', () => ({
}));

import * as configs from '../configs';
import { validateEnv } from './utils';
import { formatDateToISOString, validateEnv } from './utils';

type ValidationResult = {
success: boolean;
Expand Down Expand Up @@ -56,3 +56,26 @@ describe('validateEnv', () => {
expect(exitSpy).toHaveBeenCalledWith(1);
});
});

describe('formatDateToISOString', () => {
it('formats date to ISO string format (YYYY-MM-DD)', () => {
const testDate = new Date(Date.UTC(2024, 0, 15)); // January 15, 2024 UTC
const result = formatDateToISOString(testDate);

expect(result).toBe('2024-01-15');
});

it('handles single digit month and day with proper padding', () => {
const testDate = new Date(Date.UTC(2024, 2, 5)); // March 5, 2024 UTC
const result = formatDateToISOString(testDate);

expect(result).toBe('2024-03-05');
});

it('handles end of year date', () => {
const testDate = new Date(Date.UTC(2024, 11, 31)); // December 31, 2024 UTC
const result = formatDateToISOString(testDate);

expect(result).toBe('2024-12-31');
});
});
8 changes: 8 additions & 0 deletions workers/main/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ export function validateEnv() {
process.exit(1);
}
}

export function formatDateToISOString(date: Date): string {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');

return `${year}-${month}-${day}`;
}