Skip to content

Commit 85a78ce

Browse files
authored
Correct timestamp roundoff (#4821)
* Correct timestamp roundoff * Update entry * More tolerance
1 parent 2c2d9f2 commit 85a78ce

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2626

2727
- Fixes [#4718](https://github.com/microsoft/BotFramework-WebChat/issues/4718). In high contrast mode, Adaptive Card buttons, when pushed, should highlighted properly, by [@compulim](https://github.com/compulim), in PR [#4746](https://github.com/microsoft/BotFramework-WebChat/pull/4746)
2828
- Fixes [#4721](https://github.com/microsoft/BotFramework-WebChat/issues/4721) and [#4726](https://github.com/microsoft/BotFramework-WebChat/issues/4726). Adaptive Cards `TextBlock` heading elements should start at level 2, by [@compulim](https://github.com/compulim), in PR [#4747](https://github.com/microsoft/BotFramework-WebChat/issues/4747)
29+
- Fixes [#3699](https://github.com/microsoft/BotFramework-WebChat/issues/3699). Correcting timestamp roundoff, by [@compulim](https://github.com/compulim), in PR [#4821](https://github.com/microsoft/BotFramework-WebChat/pull/4821)
2930

3031
## [4.15.8] - 2023-06-06
3132

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="/test-harness.js"></script>
6+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
7+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
8+
</head>
9+
<body>
10+
<main id="webchat"></main>
11+
<script>
12+
run(async function () {
13+
const { directLine, store } = testHelpers.createDirectLineEmulator();
14+
const now = Date.now();
15+
16+
WebChat.renderWebChat(
17+
{
18+
directLine,
19+
store,
20+
styleOptions: {
21+
groupTimestamp: 0
22+
}
23+
},
24+
document.getElementById('webchat')
25+
);
26+
27+
await pageConditions.uiConnected();
28+
29+
// We have a few loc strings to use:
30+
// - Just now
31+
// - A minute ago
32+
// - X minutes ago
33+
// - An hour ago
34+
// - X hours ago
35+
// - Today
36+
// - Yesterday
37+
// - "Jan 2 at 12:34 PM"
38+
39+
const TIME_AGO = [
40+
['49 hours passed', 49 * 60 * 60 * 1_000, expect.stringMatching(/\sat\s/u)],
41+
['48.1 hours passed', 48.1 * 60 * 60 * 1_000, expect.stringMatching(/\sat\s/u)],
42+
['48 hours passed', 48 * 60 * 60 * 1_000, expect.stringMatching(/\sat\s/u)],
43+
['47.9 hours passed', 47.9 * 60 * 60 * 1_000, 'Yesterday'],
44+
['36 hours passed', 36 * 60 * 60 * 1_000, 'Yesterday'],
45+
['24.1 hours passed', 24.1 * 60 * 60 * 1_000, 'Yesterday'],
46+
['24 hours passed', 24 * 60 * 60 * 1_000, 'Yesterday'],
47+
['23.9 hours passed', 23.9 * 60 * 60 * 1_000, 'Today'],
48+
['12 hours passed', 12 * 60 * 60 * 1_000, 'Today'],
49+
['5.1 hours passed', 5.1 * 60 * 60 * 1_000, 'Today'],
50+
['5 hours passed', 5 * 60 * 60 * 1_000, 'Today'],
51+
['4.9 hours passed', 4.9 * 60 * 60 * 1_000, '4 hours ago'],
52+
['2 hours passed', 2 * 60 * 60 * 1_000, '2 hours ago'],
53+
['1.1 hours passed', 1.1 * 60 * 60 * 1_000, 'An hour ago'],
54+
['1 hours passed', 1 * 60 * 60 * 1_000, 'An hour ago'],
55+
['59.9 minutes passed', 59.9 * 60 * 1_000, '59 minutes ago'],
56+
['59 minutes passed', 59 * 60 * 1_000, '59 minutes ago'],
57+
['30 minutes passed', 30 * 60 * 1_000, '30 minutes ago'],
58+
['2.2 minutes passed', 2.2 * 60 * 1_000, '2 minutes ago'],
59+
['2 minutes passed', 2 * 60 * 1_000, '2 minutes ago'],
60+
['1.8 minutes passed', 1.8 * 60 * 1_000, 'A minute ago'],
61+
['1.2 minutes passed', 1.2 * 60 * 1_000, 'A minute ago'],
62+
['A minute passed', 1 * 60 * 1_000, 'A minute ago'],
63+
['0.8 minutes passed', 0.8 * 60 * 1_000, 'Just now'],
64+
['30 seconds passed', 30 * 1_000, 'Just now'],
65+
['it is now', 0, 'Just now']
66+
];
67+
68+
for (const [text, delta, expectation] of TIME_AGO) {
69+
await directLine.emulateIncomingActivity({
70+
timestamp: new Date(now - delta).toISOString(),
71+
text: `When ${text}, should show "${expectation}"`,
72+
type: 'message'
73+
});
74+
75+
const activityStatuses = pageElements.activityStatuses();
76+
const lastActivityStatus = activityStatuses[activityStatuses.length - 1];
77+
const lastTimestamp = lastActivityStatus.querySelector('[aria-hidden]').textContent;
78+
79+
expect(lastTimestamp).toEqual(expectation);
80+
}
81+
});
82+
</script>
83+
</body>
84+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */
2+
3+
describe('timestamp', () => {
4+
test('should round off correctly', () => runHTML('timestamp.roundOff.html'));
5+
});

packages/api/src/hooks/useRelativeTimeFormatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export default function useRelativeTimeFormatter(): (dateOrString: Date | string
4141
return localize('ACTIVITY_STATUS_TIMESTAMP_ONE_HOUR_AGO');
4242
} else if (deltaInHours < 5) {
4343
return relativeTimeFormatter('hour')(-deltaInHours);
44-
} else if (deltaInHours <= 24) {
44+
} else if (deltaInMs <= 24 * 3_600_000) {
4545
return localize('ACTIVITY_STATUS_TIMESTAMP_TODAY');
46-
} else if (deltaInHours <= 48) {
46+
} else if (deltaInMs <= 48 * 3_600_000) {
4747
return localize('ACTIVITY_STATUS_TIMESTAMP_YESTERDAY');
4848
}
4949

0 commit comments

Comments
 (0)