Skip to content

Commit c2246e4

Browse files
marclundgrenMarc Lundgrencompulim
authored
Fix sub-hour for dateToLocaleISOString (#5114)
* 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]>
1 parent 6a623fb commit c2246e4

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3030

3131
- 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)
3232
- 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)
33+
- 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)
3334

3435
### Changed
3536

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @jest-environment ../../../__tests__/setup/jestNodeEnvironmentWithTimezone.js
3+
* @timezone America/St_Johns
4+
*/
5+
6+
import dateToLocaleISOString from './dateToLocaleISOString';
7+
8+
test('formatting a time in Cananda, Newfoundland timezone', () => {
9+
// eslint-disable-next-line no-magic-numbers
10+
const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 567));
11+
const actual = dateToLocaleISOString(date);
12+
13+
expect(actual).toMatchInlineSnapshot(`"1999-12-31T20:42:34.567-03:30"`);
14+
});

packages/core/src/utils/dateToLocaleISOString.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ export default function dateToLocaleISOString(date: Date): string {
4545
// "yyyy-MM-DDTHH:mm:ss.fff+08:00" for GMT+08
4646
// "yyyy-MM-DDTHH:mm:ss.fffZ" for UTC
4747

48+
const absoluteTimezoneOffset = ~~Math.abs(timezoneOffset);
49+
4850
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
4951
date.getMinutes()
5052
)}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}${
51-
timezoneOffset ? `${timezoneSign}${pad(~~(Math.abs(timezoneOffset) / 60))}:${pad(timezoneOffset % 60)}` : 'Z'
53+
timezoneOffset ? `${timezoneSign}${pad(~~(absoluteTimezoneOffset / 60))}:${pad(absoluteTimezoneOffset % 60)}` : 'Z'
5254
}`;
5355
}

0 commit comments

Comments
 (0)