-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from formio/FIO-8477-fix-dayjs-timezones
FIO-8477: Fix the timezones issue in formatDate function
- Loading branch information
Showing
2 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { expect } from 'chai'; | ||
import { formatDate } from '../date'; | ||
|
||
describe('Test Date Utils', () => { | ||
it('Should format date without timezone correctly', () => { | ||
const value = '2023-04-01T12:00:00Z'; | ||
const format = 'YYYY-MM-DD'; | ||
const expected = '2023-04-01'; | ||
expect(formatDate(value, format)).to.equal(expected); | ||
}); | ||
|
||
it('Should format date in UTC timezone correctly', () => { | ||
const value = '2023-04-01T12:00:00Z'; | ||
const format = 'YYYY-MM-DD HH:mm:ss'; | ||
const timezone = 'UTC'; | ||
const expected = '2023-04-01 12:00:00 UTC'; | ||
expect(formatDate(value, format, timezone)).to.equal(expected); | ||
}); | ||
|
||
it('Should format date in a specific timezone correctly', () => { | ||
const value = '2023-04-01T12:00:00Z'; | ||
const format = 'YYYY-MM-DD HH:mm:ss'; | ||
expect(formatDate(value, format, 'America/New_York')).to.equal('2023-04-01 08:00:00 EDT'); | ||
// TODO: Fix expected value when dayjs issue is resolved | ||
// https://github.com/iamkun/dayjs/issues/1154 | ||
// expect(formatDate(value, format, 'Europe/London')).to.equal('2023-04-01 13:00:00 BST'); | ||
expect(formatDate(value, format, 'Europe/London')).to.equal('2023-04-01 13:00:00 GMT+1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters