Skip to content

Commit b6ebe09

Browse files
committed
fix: update date constructor in dateHelpers tests to avoid timezone issues
1 parent d5853fb commit b6ebe09

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/test/unit/dateHelpers.test.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
describe('Date Helpers', () => {
1616
describe('formatDateForNote', () => {
1717
it('should format date in long readable format', () => {
18-
const date = new Date('2024-10-15T12:30:00');
18+
// Use Date constructor with explicit values to avoid timezone issues
19+
const date = new Date(2024, 9, 15, 12, 30, 0); // October 15, 2024
1920
const result = formatDateForNote(date);
2021
expect(result).to.include('2024');
2122
expect(result).to.include('October');
@@ -25,11 +26,12 @@ describe('Date Helpers', () => {
2526

2627
describe('formatTimeForNote', () => {
2728
it('should format time in 12-hour format with AM/PM', () => {
28-
const morningDate = new Date('2024-10-15T09:30:00');
29+
// Use Date constructor with explicit values to avoid timezone issues
30+
const morningDate = new Date(2024, 9, 15, 9, 30, 0);
2931
const morningResult = formatTimeForNote(morningDate);
3032
expect(morningResult).to.match(/09:30 AM|9:30 AM/);
3133

32-
const afternoonDate = new Date('2024-10-15T14:30:00');
34+
const afternoonDate = new Date(2024, 9, 15, 14, 30, 0);
3335
const afternoonResult = formatTimeForNote(afternoonDate);
3436
expect(afternoonResult).to.match(/02:30 PM|2:30 PM/);
3537
});
@@ -44,7 +46,8 @@ describe('Date Helpers', () => {
4446

4547
describe('getYear', () => {
4648
it('should return year as string', () => {
47-
const date = new Date('2024-10-15');
49+
// Use Date constructor with explicit values to avoid timezone issues
50+
const date = new Date(2024, 9, 15); // October 15, 2024
4851
expect(getYear(date)).to.equal('2024');
4952
});
5053

@@ -57,18 +60,20 @@ describe('Date Helpers', () => {
5760

5861
describe('getMonth', () => {
5962
it('should return month with leading zero', () => {
60-
expect(getMonth(new Date('2024-01-15'))).to.equal('01');
61-
expect(getMonth(new Date('2024-09-15'))).to.equal('09');
62-
expect(getMonth(new Date('2024-10-15'))).to.equal('10');
63-
expect(getMonth(new Date('2024-12-15'))).to.equal('12');
63+
// Use Date constructor with explicit values to avoid timezone issues
64+
expect(getMonth(new Date(2024, 0, 15))).to.equal('01');
65+
expect(getMonth(new Date(2024, 8, 15))).to.equal('09');
66+
expect(getMonth(new Date(2024, 9, 15))).to.equal('10');
67+
expect(getMonth(new Date(2024, 11, 15))).to.equal('12');
6468
});
6569
});
6670

6771
describe('getMonthName', () => {
6872
it('should return full month name', () => {
69-
expect(getMonthName(new Date('2024-01-15'))).to.equal('January');
70-
expect(getMonthName(new Date('2024-06-15'))).to.equal('June');
71-
expect(getMonthName(new Date('2024-12-15'))).to.equal('December');
73+
// Use Date constructor with explicit values to avoid timezone issues
74+
expect(getMonthName(new Date(2024, 0, 15))).to.equal('January');
75+
expect(getMonthName(new Date(2024, 5, 15))).to.equal('June');
76+
expect(getMonthName(new Date(2024, 11, 15))).to.equal('December');
7277
});
7378
});
7479

@@ -83,9 +88,10 @@ describe('Date Helpers', () => {
8388

8489
describe('getFolderName', () => {
8590
it('should return folder name in MM-MonthName format', () => {
86-
expect(getFolderName(new Date('2024-01-15'))).to.equal('01-January');
87-
expect(getFolderName(new Date('2024-06-15'))).to.equal('06-June');
88-
expect(getFolderName(new Date('2024-12-15'))).to.equal('12-December');
91+
// Use Date constructor with explicit values to avoid timezone issues
92+
expect(getFolderName(new Date(2024, 0, 15))).to.equal('01-January');
93+
expect(getFolderName(new Date(2024, 5, 15))).to.equal('06-June');
94+
expect(getFolderName(new Date(2024, 11, 15))).to.equal('12-December');
8995
});
9096
});
9197

0 commit comments

Comments
 (0)