Skip to content

Commit

Permalink
fix(cc-input-date): fix date formatting at midnight
Browse files Browse the repository at this point in the history
Dates at midnight like `2024-02-14T00:15:25.846Z` are now formatted as
 `2024-02-14 00:15:25` instead of `2024-02-14 24:15:25`
  • Loading branch information
pdesoyres-cc committed Apr 11, 2024
1 parent 438751c commit bc67946
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/date/date-formatter.js
Expand Up @@ -30,7 +30,7 @@ function getDateTimeFormat (timezone) {
minute: '2-digit',
second: '2-digit',
fractionalSecondDigits: 3,
hour12: false,
hourCycle: 'h23',
timeZoneName: 'longOffset',
timeZone: (timezone === 'local') ? undefined : timezone,
});
Expand Down
8 changes: 8 additions & 0 deletions test/date/date-formatter.test.js
Expand Up @@ -6,6 +6,10 @@ const date = new Date('2023-03-23T14:27:33.888Z');
describe('DateFormatter', function () {
describe('format() method', function () {
describe('when format is "datetime-iso', () => {
it('should return the right time when timezone is "UTC" at midnight', function () {
expect(new DateFormatter('datetime-iso', 'UTC').format(new Date('2023-03-23T00:00:00.000Z')))
.to.equal('2023-03-23T00:00:00.000Z');
});
it('should return the right time when timezone is "UTC"', function () {
expect(new DateFormatter('datetime-iso', 'UTC').format(date))
.to.equal('2023-03-23T14:27:33.888Z');
Expand All @@ -18,6 +22,10 @@ describe('DateFormatter', function () {
});

describe('when format is "datetime-short', () => {
it('should return the right time when timezone is "UTC" at midnight', function () {
expect(new DateFormatter('datetime-short', 'UTC').format(new Date('2023-03-23T00:00:00.000Z')))
.to.equal('2023-03-23 00:00:00');
});
it('should return the right time when timezone is "UTC"', function () {
expect(new DateFormatter('datetime-short', 'UTC').format(date))
.to.equal('2023-03-23 14:27:33');
Expand Down

0 comments on commit bc67946

Please sign in to comment.