online-judge icon indicating copy to clipboard operation
online-judge copied to clipboard

Increase precision on relative time offsets

Open int-y1 opened this issue 2 years ago • 3 comments

Fixes #1846. Makes moment.js redundant. The new relative time messages will be:

  • 1 second to 119 seconds
  • 2 minutes to 179 minutes
  • 3 hours to 47 hours
  • 2 days to 99 days

This diff is friendly towards i18n. German example:

Capture

As a failsafe, always use absolute time if the browser doesn't support Math.trunc and Intl.RelativeTimeFormat. For example, IE11.

int-y1 avatar Aug 18 '22 06:08 int-y1

Codecov Report

Merging #1990 (4c7f6d0) into master (1bd9be0) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1990   +/-   ##
=======================================
  Coverage   46.51%   46.51%           
=======================================
  Files         236      236           
  Lines       13085    13085           
=======================================
  Hits         6086     6086           
  Misses       6999     6999           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Aug 18 '22 06:08 codecov-commenter

Fun fact: Intl.RelativeTimeFormat supports fractional amounts, e.g. rtf.format(-3.14159, 'minute') becomes '3.142 minutes ago'.

I only used integer amounts in this pr, because there's no need for fractional amounts right now.

int-y1 avatar Aug 19 '22 10:08 int-y1

2 minutes to 179 minutes

👀

Xyene avatar Aug 20 '22 15:08 Xyene