-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dates and times are messed up when the day is same number as current day, no matter what year or month it was #11663
Comments
As i am trying to learn to better understand and maybe one day contribute more than just with a few bug issues, i tried to track this bug down in the source code. I saw this in packages/rocketchat-ui/client/views/app/directory.js, line 15 function directorySearch(config, cb) {
return Meteor.call('browseChannels', config, (err, result) => {
cb(result && result.results && result.results.length && result.results.map(result => {
if (config.type === 'channels') {
return {
name: result.name,
users: result.usersCount || 0,
createdAt: timeAgo(result.ts),
lastMessage: result.lastMessage && timeAgo(result.lastMessage.ts),
description: result.description,
archived: result.archived,
topic: result.topic
};
}
if (config.type === 'users') {
return {
name: result.name,
username: result.username,
createdAt: timeAgo(result.createdAt)
};
}
}));
});
} My understanding is that the bug probably comes from the function timeAgo(time) {
if (!time) {
return;
}
const now = new Date();
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
return (now.getDate() === time.getDate() && moment(time).format('LT')) || (yesterday.getDate() === time.getDate() && t('yesterday')) || moment(time).format('MMM D, YYYY');
} A similar function is defined in packages/rocketchat-ui-sidenav/client/sidebarItem.js where timeAgo function is defined line 29 function timeAgo(time) {
const now = new Date();
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
return (
now.getDate() === time.getDate() && moment(time).format('LT') ||
yesterday.getDate() === time.getDate() && t('yesterday') ||
moment(time).format('L')
);
} The return element is probably where it fucks up...i guess? return (now.getDate() === time.getDate() && moment(time).format('LT')) || (yesterday.getDate() === time.getDate() && t('yesterday')) || moment(time).format('MMM D, YYYY'); |
hey @Julianoe, thanks for this really good deep dive on the issue! |
Fix #11663 Adding `timeAgo` function to a `helpers` file so we can test it because just importing it from the previous file will cause an error `Template is not defined`. I reproduced the mentioned case on a test.
#11663 Compares day, month and year to show the correct create date of channels and users.
…ction (#11946) Related with #11663, but I added a bug removing `t` function on this PR 😬 #11728 Now we're translating 🗣 🌎 🌍 🌏 ![screen shot 2018-09-04 at 10 20 55 am](https://user-images.githubusercontent.com/2047941/45033836-30e28000-b02c-11e8-8726-96d8780eb92b.png)
…etChat#11682) RocketChat#11663 Compares day, month and year to show the correct create date of channels and users.
#11663 Compares day, month and year to show the correct create date of channels and users.
Description:
In the "directory" page the dates for last message posted and creating date are wrong. Same thing goes for users creation dates !
Examples : what i have
Examples : what is displayed
Consider this is take the 3 of august 2018 at 1:54 (am)
what would be excpected i guess :
Obviously there is something wrong in the code that takes the number of the day but does takes in account the month or year
Server Setup Information:
Additional context
(damn those US/UK date and time formats)
The text was updated successfully, but these errors were encountered: