mirror of https://github.com/ghostfolio/ghostfolio
committed by
GitHub
7 changed files with 111 additions and 4 deletions
@ -0,0 +1,28 @@ |
|||
/** |
|||
* @jest-environment <rootDir>/../../apps/api/jest-environment-tz.js |
|||
* @jest-environment-options {"timeZone": "Pacific/Auckland"} |
|||
*/ |
|||
import { |
|||
DATE_FORMAT, |
|||
getLocalDateFromUtcDate |
|||
} from '@ghostfolio/common/helper'; |
|||
|
|||
import { format } from 'date-fns'; |
|||
|
|||
describe('Helper in a time zone ahead of UTC', () => { |
|||
describe('Get local date from UTC date', () => { |
|||
it.each([ |
|||
['in summer time', '2026-01-01', '2025-12-31T11:00:00.000Z'], |
|||
['at the end of summer time', '2026-04-05', '2026-04-04T11:00:00.000Z'], |
|||
['in standard time', '2026-07-01', '2026-06-30T12:00:00.000Z'], |
|||
['at the start of summer time', '2026-09-27', '2026-09-26T12:00:00.000Z'] |
|||
])('Preserve the calendar date %s', (_, dateString, localMidnight) => { |
|||
const localDate = getLocalDateFromUtcDate( |
|||
new Date(`${dateString}T00:00:00.000Z`) |
|||
); |
|||
|
|||
expect(format(localDate, DATE_FORMAT)).toEqual(dateString); |
|||
expect(localDate).toEqual(new Date(localMidnight)); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,28 @@ |
|||
/** |
|||
* @jest-environment <rootDir>/../../apps/api/jest-environment-tz.js |
|||
* @jest-environment-options {"timeZone": "America/New_York"} |
|||
*/ |
|||
import { |
|||
DATE_FORMAT, |
|||
getLocalDateFromUtcDate |
|||
} from '@ghostfolio/common/helper'; |
|||
|
|||
import { format } from 'date-fns'; |
|||
|
|||
describe('Helper in a time zone behind UTC', () => { |
|||
describe('Get local date from UTC date', () => { |
|||
it.each([ |
|||
['in standard time', '2026-01-01', '2026-01-01T05:00:00.000Z'], |
|||
['at the start of summer time', '2026-03-08', '2026-03-08T05:00:00.000Z'], |
|||
['in summer time', '2026-07-01', '2026-07-01T04:00:00.000Z'], |
|||
['at the end of summer time', '2026-11-01', '2026-11-01T04:00:00.000Z'] |
|||
])('Preserve the calendar date %s', (_, dateString, localMidnight) => { |
|||
const localDate = getLocalDateFromUtcDate( |
|||
new Date(`${dateString}T00:00:00.000Z`) |
|||
); |
|||
|
|||
expect(format(localDate, DATE_FORMAT)).toEqual(dateString); |
|||
expect(localDate).toEqual(new Date(localMidnight)); |
|||
}); |
|||
}); |
|||
}); |
|||
Loading…
Reference in new issue