Skip to content

Commit 61ee183

Browse files
dgp1130pkozlowski-opensource
authored andcommitted
test: construct local Date objects to fix timezone flakiness
Replaced testing constructions of `Date` objects from `formatDate` tests from plain ISO strings over to 'new Date(year, month, date)'. Instantiating 'new Date("2024-01-01")' parses the string strictly as UTC midnight ("2024-01-01T00:00:00.000Z"). When local operations execute (such as calculating `getThursdayThisIsoWeek` boundaries), the UTC date shifts relative to the executing machine's timezone. For example, in PST (GMT-8), that date translates exactly to 'December 31st 16:00:00', pushing week boundaries backwards. By wrapping date constructs explicitly as 'new Date(2024, 0, 1)', it natively guarantees local midnight execution and prevents boundaries shifting on global CI Remote Build Execution (RBE) workers. Example (from a machine in PST): ```javascript > new Date('2024-01-01') Sun Dec 31 2023 16:00:00 GMT-0800 (Pacific Standard Time) > new Date(2024, 0, 1) Mon Jan 01 2024 00:00:00 GMT-0800 (Pacific Standard Time) ```
1 parent a1385ad commit 61ee183

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/common/test/i18n/format_date_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,13 @@ describe('Format date', () => {
524524

525525
it('should return thursday date of the same week', () => {
526526
// Dec. 31st is a Sunday, last day of the last week of 2023
527-
expect(getThursdayThisIsoWeek(new Date('2023-12-31'))).toEqual(new Date('2023-12-28'));
527+
expect(getThursdayThisIsoWeek(new Date(2023, 11, 31))).toEqual(new Date(2023, 11, 28));
528528

529529
// Dec. 29th is a Thursday
530-
expect(getThursdayThisIsoWeek(new Date('2022-12-29'))).toEqual(new Date('2022-12-29'));
530+
expect(getThursdayThisIsoWeek(new Date(2022, 11, 29))).toEqual(new Date(2022, 11, 29));
531531

532532
// Jan 01st is a Monday
533-
expect(getThursdayThisIsoWeek(new Date('2024-01-01'))).toEqual(new Date('2024-01-04'));
533+
expect(getThursdayThisIsoWeek(new Date(2024, 0, 1))).toEqual(new Date(2024, 0, 4));
534534
});
535535
});
536536
});

0 commit comments

Comments
 (0)