From 6bdce99a34985d2bc9c07c230cf9bd5f7dcd5f15 Mon Sep 17 00:00:00 2001 From: "anatoly.shipitz" Date: Wed, 30 Jul 2025 18:50:44 +0200 Subject: [PATCH 1/3] Add date formatting utility function (#76) - Introduced a new function `formatDateToISOString` in `utils.ts` to convert Date objects to ISO 8601 string format. This utility enhances date handling across the application, ensuring consistent date formatting. These changes improve the utility functions available for date manipulation, facilitating better integration with APIs and data processing. --- workers/main/src/common/utils.ts | 8 ++++++++ 1 file changed, 8 insertions(+) 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}`; +} From 0a3e523623f20a74bec4ca3f27761c99adcbfd46 Mon Sep 17 00:00:00 2001 From: "anatoly.shipitz" Date: Thu, 31 Jul 2025 17:02:36 +0200 Subject: [PATCH 2/3] Enhance test coverage for date formatting utility - Added unit tests for the newly introduced `formatDateToISOString` function in `utils.test.ts`. The tests cover various scenarios, including formatting standard dates, handling single-digit months and days, and ensuring correct formatting for end-of-year dates. These changes improve the reliability of the date formatting utility by ensuring it behaves as expected across different input cases. --- workers/main/src/common/utils.test.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/workers/main/src/common/utils.test.ts b/workers/main/src/common/utils.test.ts index 9efeaba..349f1f9 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('2024-01-15T10:30:00Z'); + const result = formatDateToISOString(testDate); + + expect(result).toBe('2024-01-15'); + }); + + it('handles single digit month and day with proper padding', () => { + const testDate = new Date('2024-03-05T10:30:00Z'); + const result = formatDateToISOString(testDate); + + expect(result).toBe('2024-03-05'); + }); + + it('handles end of year date', () => { + const testDate = new Date(2024, 11, 31); // December 31, 2024 (month is 0-indexed) + const result = formatDateToISOString(testDate); + + expect(result).toBe('2024-12-31'); + }); +}); From ca0d349de372081dd61603722469a8792435efe6 Mon Sep 17 00:00:00 2001 From: "anatoly.shipitz" Date: Thu, 31 Jul 2025 17:09:51 +0200 Subject: [PATCH 3/3] Refactor date tests for consistency in UTC format - Updated test cases in `utils.test.ts` for the `formatDateToISOString` function to use UTC format for date initialization. This change ensures consistency in date handling across different environments and improves the reliability of the tests. These modifications enhance the accuracy of date formatting tests by standardizing the date input format. --- workers/main/src/common/utils.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/workers/main/src/common/utils.test.ts b/workers/main/src/common/utils.test.ts index 349f1f9..6146e44 100644 --- a/workers/main/src/common/utils.test.ts +++ b/workers/main/src/common/utils.test.ts @@ -59,21 +59,21 @@ describe('validateEnv', () => { describe('formatDateToISOString', () => { it('formats date to ISO string format (YYYY-MM-DD)', () => { - const testDate = new Date('2024-01-15T10:30:00Z'); + 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('2024-03-05T10:30:00Z'); + 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(2024, 11, 31); // December 31, 2024 (month is 0-indexed) + const testDate = new Date(Date.UTC(2024, 11, 31)); // December 31, 2024 UTC const result = formatDateToISOString(testDate); expect(result).toBe('2024-12-31');