Commit d78e2991 authored by Sean Hammond's avatar Sean Hammond

Display "secs", "mins", "hrs" when n > 1

When dealing with more than one second, minute or hour display secs,
mins or hrs instead of sec, min or hr.

In the case of secs it's always more than 1.
parent 2beca22c
...@@ -11,11 +11,11 @@ var year = day * 365; ...@@ -11,11 +11,11 @@ var year = day * 365;
var FIXTURES_TO_FUZZY_STRING = [ var FIXTURES_TO_FUZZY_STRING = [
[10, 'Just now'], [10, 'Just now'],
[29, 'Just now'], [29, 'Just now'],
[49, '49 sec'], [49, '49 secs'],
[minute + 5, '1 min'], [minute + 5, '1 min'],
[3 * minute + 5, '3 min'], [3 * minute + 5, '3 mins'],
[hour, '1 hr'], [hour, '1 hr'],
[4 * hour, '4 hr'], [4 * hour, '4 hrs'],
[27 * hour, '1 Jan'], [27 * hour, '1 Jan'],
[3 * day + 30 * minute, '1 Jan'], [3 * day + 30 * minute, '1 Jan'],
[6 * month + 2 * day, '1 Jan'], [6 * month + 2 * day, '1 Jan'],
......
...@@ -28,15 +28,29 @@ function delta(date, now) { ...@@ -28,15 +28,29 @@ function delta(date, now) {
} }
function nSec(date, now) { function nSec(date, now) {
return '{} sec'.replace('{}', Math.floor(delta(date, now))); return '{} secs'.replace('{}', Math.floor(delta(date, now)));
} }
function nMin(date, now) { function nMin(date, now) {
return '{} min'.replace('{}', Math.floor(delta(date, now) / minute)); var n = Math.floor(delta(date, now) / minute);
var template = '{} min';
if (n > 1) {
template = template + 's';
}
return template.replace('{}', n);
} }
function nHr(date, now) { function nHr(date, now) {
return '{} hr'.replace('{}', Math.floor(delta(date, now) / hour)); var n = Math.floor(delta(date, now) / hour);
var template = '{} hr';
if (n > 1) {
template = template + 's';
}
return template.replace('{}', n);
} }
// Cached DateTimeFormat instances, // Cached DateTimeFormat instances,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment