Skip to content

Commit 4f575b6

Browse files
authored
Fix 3279: Relative timestamp showing date before yesterday should not error out (#3282)
* Fix relative timestamp on date before yesterday * Add test * Update entry
1 parent 367b429 commit 4f575b6

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2929
### Fixes
3030

3131
- Fixes [#3265](https://github.com/microsoft/BotFramework-WebChat/issues/3265). Fix styling specificity regression on microphone button, by [@corinagum](https://github.com/corinagum) in PR [#3276](https://github.com/microsoft/BotFramework-WebChat/pull/3276)
32+
- Fixes [#3279](https://github.com/microsoft/BotFramework-WebChat/issues/3279). Fix relative timestamp errored out when showing a time before yesterday, by [@compulim](https://github.com/compulim) in PR [#3282](https://github.com/microsoft/BotFramework-WebChat/pull/3282)
3233

3334
### Samples
3435

@@ -109,7 +110,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
109110
- After stripping Markdown syntax for accessibility labels, cache the result to improve rendering performance.
110111
- Skip stripping Markdown for non-Markdown text content.
111112
- Fixes [#3155](https://github.com/microsoft/BotFramework-WebChat/issues/3155). Patch incoming activities with null fields, by [@compulim](https://github.com/compulim) in PR [#3154](https://github.com/microsoft/BotFramework-WebChat/pull/3154)
112-
- Fixes [#2669](https://github.com/microsoft/BotFramework-WebChat/issues/2669) and [[#3136](https://github.com/microsoft/BotFramework-WebChat/issues/3136). The "New messages" button will be accessible through <kbd>TAB</kbd> key, inbetween the last read and first unread activity, by [@compulim](https://github.com/compulim) in PR [#3150](https://github.com/microsoft/BotFramework-WebChat/issues/3150).
113+
- Fixes [#2669](https://github.com/microsoft/BotFramework-WebChat/issues/2669) and [#3136](https://github.com/microsoft/BotFramework-WebChat/issues/3136). The "New messages" button will be accessible through <kbd>TAB</kbd> key, inbetween the last read and first unread activity, by [@compulim](https://github.com/compulim) in PR [#3150](https://github.com/microsoft/BotFramework-WebChat/issues/3150).
113114
- After the "New message" button is clicked, focus will be moved to the first interactive UI of unread activity or the send box.
114115
- Fixes [#3135](https://github.com/microsoft/BotFramework-WebChat/issues/3135). If the current widget is disabled, it will keep focus until the next <kbd>TAB</kbd> key is pressed, by [@compulim](https://github.com/compulim) in PR [#3150](https://github.com/microsoft/BotFramework-WebChat/pull/3150)
115116

@@ -186,11 +187,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
186187

187188
### Fixed
188189

189-
- Fixes [#3075](https://github.com/microsoft/BotFramework-WebChat/issues/3075). Fix usability issues around accessibility, by [@compulim](https://github.com/compulim) in PR [#3076](https://github.com/microsoft/BotFramework-WebChat/issue/3076)
190+
- Fixes [#3075](https://github.com/microsoft/BotFramework-WebChat/issues/3075). Fix usability issues around accessibility, by [@compulim](https://github.com/compulim) in PR [#3076](https://github.com/microsoft/BotFramework-WebChat/pull/3076)
190191
- Fix timestamp should not be narrated more than once.
191192
- Associate the activity text with its attachments, by adding a `role="region"` to the activity DOM element.
192-
- Fixes [#3074](https://github.com/microsoft/BotFramework-WebChat/issues/3074). Keep `props.locale` when sending to the bot, by [@compulim](https://github.com/compulim) in PR [#3095](https://github.com/microsoft/BotFramework-WebChat/issue/3095)
193-
- Fixes [#3096](https://github.com/microsoft/BotFramework-WebChat/issues/3096). Use `<ScreenReaderText>` instead of `aria-label` for message bubbles, by [@compulim](https://github.com/compulim) in PR [#3097](https://github.com/microsoft/BotFramework-WebChat/issue/3097)
193+
- Fixes [#3074](https://github.com/microsoft/BotFramework-WebChat/issues/3074). Keep `props.locale` when sending to the bot, by [@compulim](https://github.com/compulim) in PR [#3095](https://github.com/microsoft/BotFramework-WebChat/pull/3095)
194+
- Fixes [#3096](https://github.com/microsoft/BotFramework-WebChat/issues/3096). Use `<ScreenReaderText>` instead of `aria-label` for message bubbles, by [@compulim](https://github.com/compulim) in PR [#3097](https://github.com/microsoft/BotFramework-WebChat/pull/3097)
194195

195196
## [4.8.0] - 2020-03-05
196197

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<script crossorigin="anonymous" src="/__dist__/testharness.js"></script>
5+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
6+
</head>
7+
<body>
8+
<div id="webchat"></div>
9+
<script type="text/babel" data-presets="env,stage-3,react">
10+
const { conditions, createStore, expect, host, pageObjects, timeouts, token, updateIn } = window.WebChatTest;
11+
12+
function mapObservable(observable, { next }) {
13+
return new Observable(observer => {
14+
const subscription = observable.subscribe({
15+
complete: observer.complete.bind(observer),
16+
error: observer.error.bind(observable),
17+
next: value => observer.next(next(value))
18+
});
19+
20+
return subscription.unsubscribe.bind(subscription);
21+
});
22+
}
23+
24+
(async function() {
25+
function createDirectLineForTest(options) {
26+
const workingDirectLine = window.WebChat.createDirectLine(options);
27+
28+
return {
29+
...workingDirectLine,
30+
activity$: mapObservable(workingDirectLine.activity$, {
31+
next: value => ({
32+
...value,
33+
34+
// Substract 3 days from the timestamp
35+
timestamp: new Date(new Date(value.timestamp).getTime() - 86400000 * 3).toISOString()
36+
})
37+
}),
38+
postActivity: workingDirectLine.postActivity.bind(workingDirectLine)
39+
};
40+
}
41+
42+
window.WebChat.renderWebChat(
43+
{
44+
directLine: createDirectLineForTest({ token: await token.fetchDirectLineToken() }),
45+
store: createStore(),
46+
styleOptions: {
47+
sendTimeout: 5000
48+
}
49+
},
50+
document.getElementById('webchat')
51+
);
52+
53+
await pageObjects.wait(conditions.uiConnected(), timeouts.directLine);
54+
await pageObjects.sendMessageViaSendBox('echo Hello, World!', { waitForSend: false });
55+
56+
await host.done();
57+
})().catch(async err => {
58+
console.error(err);
59+
60+
await host.error(err);
61+
});
62+
</script>
63+
</body>
64+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @jest-environment ./__tests__/html/__jest__/WebChatEnvironment.js
3+
*/
4+
5+
describe('timestamp', () => {
6+
test('showing date before yesterday', () => runHTMLTest('timestamp.beforeYesterday.html'));
7+
});

packages/component/src/hooks/useLocalizeDate.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ import useLanguage from './useLanguage';
22

33
import getLocaleString from '../Localization/getLocaleString';
44

5+
let deprecationNotesShown;
6+
57
export default function useLocalizeDate(date) {
8+
if (!deprecationNotesShown) {
9+
console.warn(
10+
'botframework-webchat: useLocalizeDate() is deprecated. Please use the useDateFormatter() hooks instead. This function will be removed on or after 2022-02-12.'
11+
);
12+
13+
deprecationNotesShown = true;
14+
}
15+
616
const [language] = useLanguage();
717

818
return getLocaleString(date, language);

packages/component/src/hooks/useRelativeTimeFormatter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import { useMemo } from 'react';
44

5-
import getLocaleString from '../Localization/getLocaleString';
5+
import useDateFormatter from './useDateFormatter';
66
import useLocalizedGlobalize from './internal/useLocalizedGlobalize';
77
import useLocalizer from './useLocalizer';
88

99
export default function useRelativeTimeFormatter() {
10+
const formatDate = useDateFormatter();
1011
const localize = useLocalizer();
1112
const [globalize] = useLocalizedGlobalize();
1213

@@ -42,7 +43,7 @@ export default function useRelativeTimeFormatter() {
4243
return localize('ACTIVITY_STATUS_TIMESTAMP_YESTERDAY');
4344
}
4445

45-
return getLocaleString(date, 'en-US');
46+
return formatDate(date);
4647
};
4748
}, [localize, globalize]);
4849
}

0 commit comments

Comments
 (0)