Skip to content

Commit

Permalink
Fix sub-hour for dateToLocaleISOString (#5114)
Browse files Browse the repository at this point in the history
* add test that has a broken case. next commit will be the fix

* fix. plus since this is a negative offset, the date time needs to be adjusted to dec 31s 1999 in this test example

* Add entry

---------

Co-authored-by: Marc Lundgren <[email protected]>
Co-authored-by: William Wong <[email protected]>
  • Loading branch information
3 people authored Apr 8, 2024
1 parent 6a623fb commit c2246e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Fixes [#5050](https://github.com/microsoft/BotFramework-WebChat/issues/5050). Fixed focus should not blur briefly after tapping on a suggested action, by [@compulim](https://github.com/compulim), in PR [#5097](https://github.com/microsoft/BotFramework-WebChat/issues/pull/5097)
- Fixes [#5111](https://github.com/microsoft/BotFramework-WebChat/issues/5111). Fixed keyboard help screen to use HTML description list, by [@compulim](https://github.com/compulim), in PR [#5116](https://github.com/microsoft/BotFramework-WebChat/issues/pull/5116)
- Fixes [#5080](https://github.com/microsoft/BotFramework-WebChat/issues/5080). Fixed `dateToLocaleISOString` for handling sub-hour, by [@marclundgren](https://github.com/marclundgren), in PR [#5114](https://github.com/microsoft/BotFramework-WebChat/pull/5114)

### Changed

Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/utils/dateToLocaleISOString.newfoundland.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @jest-environment ../../../__tests__/setup/jestNodeEnvironmentWithTimezone.js
* @timezone America/St_Johns
*/

import dateToLocaleISOString from './dateToLocaleISOString';

test('formatting a time in Cananda, Newfoundland timezone', () => {
// eslint-disable-next-line no-magic-numbers
const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 567));
const actual = dateToLocaleISOString(date);

expect(actual).toMatchInlineSnapshot(`"1999-12-31T20:42:34.567-03:30"`);
});
4 changes: 3 additions & 1 deletion packages/core/src/utils/dateToLocaleISOString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export default function dateToLocaleISOString(date: Date): string {
// "yyyy-MM-DDTHH:mm:ss.fff+08:00" for GMT+08
// "yyyy-MM-DDTHH:mm:ss.fffZ" for UTC

const absoluteTimezoneOffset = ~~Math.abs(timezoneOffset);

return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
date.getMinutes()
)}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}${
timezoneOffset ? `${timezoneSign}${pad(~~(Math.abs(timezoneOffset) / 60))}:${pad(timezoneOffset % 60)}` : 'Z'
timezoneOffset ? `${timezoneSign}${pad(~~(absoluteTimezoneOffset / 60))}:${pad(absoluteTimezoneOffset % 60)}` : 'Z'
}`;
}

0 comments on commit c2246e4

Please sign in to comment.