Skip to content
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

Closed
Julianoe opened this issue Aug 2, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@Julianoe
Copy link

Julianoe commented Aug 2, 2018

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

  • arts channel creation date : 31 may 2017
  • arts channel last message : 2 june 2018, 13:29
  • webdesign channel creation date : 2 june 2017
  • webdeisgn channel last message : 3 june 2018, 13:53

Examples : what is displayed

Consider this is take the 3 of august 2018 at 1:54 (am)

capture d ecran de 2018-08-03 01-49-18

  • arts channel creation date : 31 may 2017
  • arts channel last message : "yesterday"
  • webdesign channel creation date : "yesterday"
  • webdeisgn channel last message : 13:53

what would be excpected i guess :

  • arts channel creation date : 31 may 2017
  • arts channel last message : 2 june 2018
  • webdesign channel creation date : 2 june 2017
  • webdeisgn channel last message : 3 june 2018

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:

  • Version of Rocket.Chat Server: 0.68.3
  • Operating System: linux ubuntu 16.04
  • Deployment Method: docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog: disabled (?)
  • NodeJS Version: v8.11.3
  • MongoDB Version: 130 (?)

Additional context

(damn those US/UK date and time formats)

@Julianoe Julianoe changed the title Directory displaying posts from last month on the exact same day as if it was today Directory dates and times are messed up when the day is same number as current day, no matter what year or month it was Aug 2, 2018
@Julianoe
Copy link
Author

Julianoe commented Aug 3, 2018

As a matter of fact it seems to only be a front-end problem because the channels are well ordered when "sorted by creation date", even if displayed info is wrong (see screenshot below)

capture d ecran de 2018-08-03 02-00-58

@Julianoe Julianoe changed the title Directory dates and times are messed up when the day is same number as current day, no matter what year or month it was Dates and times are messed up when the day is same number as current day, no matter what year or month it was Aug 3, 2018
@Julianoe
Copy link
Author

Julianoe commented Aug 3, 2018

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 timeAgo() function in the same file line 4

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');

@rssilva
Copy link
Contributor

rssilva commented Aug 10, 2018

hey @Julianoe, thanks for this really good deep dive on the issue!
Do you mind to test this branch and check if this solves?

ggazzo pushed a commit that referenced this issue Aug 13, 2018
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.
ggazzo pushed a commit that referenced this issue Aug 14, 2018
#11663 
Compares day, month and year to show the correct create date of channels and users.
ggazzo pushed a commit that referenced this issue Sep 18, 2018
…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)
Kishn0109 pushed a commit to Kishn0109/Rocket.Chat that referenced this issue May 26, 2023
…etChat#11682)

RocketChat#11663 
Compares day, month and year to show the correct create date of channels and users.
janainaCoelhoRocketchat pushed a commit that referenced this issue Aug 18, 2023
#11663 
Compares day, month and year to show the correct create date of channels and users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants