-
Improvement
-
Resolution: Won't Do
-
Minor
-
None
-
3.4
-
None
-
MOODLE_34_STABLE
The output of format_time doesn't use very natural language and there is a whole bunch of ways this could be way better and bring it in line which common norms elsewhere on the interwebs:
More natural language
Some examples are:
"11 mins 24 secs" - most people would just say "11 mins" and not care about the remainder.
It gets worse with either small or large numbers:
"1 min 20 seconds" -> "80 seconds"
"1 day and 8 hours" -> "32 hours"
"1 week and 2 days" -> "9 days"
"3.6000000000058 secs" -> "4 secs" (real example)
Generally if the first significant number is 1 then most people would think in the smaller units.
Also there should be a distinction between time deltas vs points in time. eg all of the examples above are time deltas, but if it was a point in time then we can be more natural eg:
"12 hours and 10 mins ago" -> "12 hours ago" (If the delta is still today)
"12 hours and 10 mins ago" -> "yesterday" (If the delta wraps before midnight)
Nobody should be manually constructing sentences by tacking on "... ago" or "in ...", or "now"
Less significant figures
I often find myself calling this function and then cutting it in half to get just the 'first significant figure' of the time delta. But it would be better if this was an option that could be passed in as it should affect the display logic as above.
Optional abbreviations
Often you quite often see abbreviated times in places where screen real estate is tight:
3d
11h
6m
10s
Titles / tooltips
But while these are good at a glance you also want to hover and get the exact date.
Point in time language modifiers
If this is something based on a set point in time you almost always need to tack on some extra string logic around it so you get "10 hours ago" or "in 5 mins", it would be great to have a convenience renderer for this because it is repeatedly used so often.
If it represents a point in time and not just a time period then quite often you'd prefer something like:
"Yesterday" instead of "26 hours ago"
Live updating
If it is a point in time then as soon as you post it then it should say "Just now" and then in a minute it should say "A minute ago" and then "2 mins ago" etc. Or if it's say a quiz opening in 3 hours then "In 2 hours" and then if you leave the page open it should tick over to stuff like "In 42 mins"
Tolerance for clock skew / accuracy
It's hard to get things like this accurate down to the second, so quite often if it's a matter of seconds then it would probably just say "now" if it's a point in time.
And of course all of this would be timezone aware.
Suggestions:
There are really great js libs for handling this stuff like MomentJS:
So I reckon we need a new renderer which leverages it. It's not critical that the rendered date format is identical to the live updated date, but ideally these would be pretty close in most cases. But that means re-implementing some of the MomentJS logic inside php / mustache land too.
- has been marked as being related by
-
MDL-72283 Allow customisation of Redis session handler errors
-
- Closed
-