Skip to content

Conversation

@buildwithricky
Copy link

@buildwithricky buildwithricky commented Oct 31, 2025

Purpose

Implemented the logic to show 'Just now' instead of '0 seconds ago' when the difference is under one second.
Users can now see 'just now' when an edit happens.

Proposal

  • Fixed the '0 seconds ago issue' to show 'Just Now' when edits happen.
Screenshot 2025-10-31 at 21 40 22

External contributions

Thank you for your contribution! 🎉

Please ensure the following items are checked before submitting your pull request:

  • I have read and followed the contributing guidelines
  • I have read and agreed to the Code of Conduct
  • I have signed off my commits with git commit --signoff (DCO compliance)
  • I have signed my commits with my SSH or GPG key (git commit -S)
  • My commit messages follow the required format: <gitmoji>(type) title description

Implemented the logic to show 'Just now' instead of '0 seconds ago' when the difference is under one second.

Signed-off-by: buildwithricky <nwakezepatrick@gmail.com>
@buildwithricky
Copy link
Author

@rvveber

@buildwithricky
Copy link
Author

@rvveber where you able to review this yet the workflow hasn't started

@rvveber rvveber self-assigned this Nov 11, 2025
Comment on lines +25 to +37
const dateTime = DateTime.fromISO(date).setLocale(i18n.language);
const relative = dateTime.toRelative();
if (relative) {
const diffInSeconds = Math.abs(dateTime.diffNow('seconds').seconds);
if (diffInSeconds < 1) {
return t('just now');
}
if (relative.includes('0 seconds') || relative.includes('0 second') ||
relative.match(/0\s*(second|seconde|segundo|)/i)) {
return t('just now');
}
}
return relative;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

  • Regex is unnecessary, we have input data so we should use it to calculate the difference
  • Locale is only required for displaying and so it would be more readable to set it when displaying
  • Always best to name variables explicitly and concisely
  • Lets use a timeframe of 5 seconds to display just now for everything below it

Suggestion

  const dateToCompare = DateTime.fromISO(date);
  if (!dateToCompare.isValid) return '';
  const dateNow = DateTime.now();
  const differenceInSeconds = dateNow.diff(dateToCompare).as('seconds');

  return Math.abs(differenceInSeconds) >= 5
    ? dateToCompare.toRelative({ base: dateNow, locale: i18n.language })
    : t('just now');

Agree / Disagree?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants