diff --git a/workers/main/src/common/utils.test.ts b/workers/main/src/common/utils.test.ts index 9efeaba..6146e44 100644 --- a/workers/main/src/common/utils.test.ts +++ b/workers/main/src/common/utils.test.ts @@ -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; @@ -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'); + }); +}); diff --git a/workers/main/src/common/utils.ts b/workers/main/src/common/utils.ts index 9d945c8..35387f5 100644 --- a/workers/main/src/common/utils.ts +++ b/workers/main/src/common/utils.ts @@ -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}`; +}