feat: Show date along with time in messages (#1748)

This commit is contained in:
Pranav Raj S 2021-02-11 12:10:08 +05:30 committed by GitHub
parent a880845d2b
commit d92a6a3078
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 4 deletions

View file

@ -131,7 +131,7 @@ export default {
return !this.data.message_type ? 'left' : 'right';
},
readableTime() {
return this.messageStamp(this.data.created_at);
return this.messageStamp(this.data.created_at, 'LLL d, h:mm a');
},
isBubble() {
return [0, 1, 3].includes(this.data.message_type);

View file

@ -0,0 +1,10 @@
import TimeMixin from '../time';
describe('#messageStamp', () => {
it('returns correct value', () => {
expect(TimeMixin.methods.messageStamp(1612971343)).toEqual('3:35 PM');
expect(TimeMixin.methods.messageStamp(1612971343, 'LLL d, h:mm a')).toEqual(
'Feb 10, 3:35 PM'
);
});
});

View file

@ -1,13 +1,12 @@
/* eslint no-console: 0 */
import fromUnixTime from 'date-fns/fromUnixTime';
import format from 'date-fns/format';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
export default {
methods: {
messageStamp(time) {
messageStamp(time, dateFormat = 'h:mm a') {
const unixTime = fromUnixTime(time);
return format(unixTime, 'h:mm a');
return format(unixTime, dateFormat);
},
dynamicTime(time) {
const unixTime = fromUnixTime(time);

View file

@ -30,4 +30,5 @@ module.exports = {
'**/app/javascript/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
],
testURL: 'http://localhost/',
globalSetup: './jest.setup.js',
};

3
jest.setup.js Normal file
View file

@ -0,0 +1,3 @@
module.exports = async () => {
process.env.TZ = 'UTC';
};