Commit faa3f877 authored by Sean Hammond's avatar Sean Hammond

Change BREAKPOINTS to an array of objects

Clearer than using an array of arrays.
parent 54d51376
...@@ -90,19 +90,43 @@ function dayAndMonthAndYear(date) { ...@@ -90,19 +90,43 @@ function dayAndMonthAndYear(date) {
} }
var BREAKPOINTS = [ var BREAKPOINTS = [
[lessThanThirtySecondsAgo, function () {return 'Just now';}, 1], {
[lessThanOneMinuteAgo, nSec, 1], test: lessThanThirtySecondsAgo,
[lessThanOneHourAgo, nMin, minute], format: function () {return 'Just now';},
[lessThanOneDayAgo, nHr, hour], nextUpdate: 1
[thisYear, dayAndMonth, null], },
[function () {return true;}, dayAndMonthAndYear, null] {
test: lessThanOneMinuteAgo,
format: nSec,
nextUpdate: 1
},
{
test: lessThanOneHourAgo,
format: nMin,
nextUpdate: minute
},
{
test: lessThanOneDayAgo,
format: nHr,
nextUpdate: hour
},
{
test: thisYear,
format: dayAndMonth,
nextUpdate: null
},
{
test: function () {return true;},
format: dayAndMonthAndYear,
nextUpdate: null
}
]; ];
function getBreakpoint(date, now) { function getBreakpoint(date, now) {
var breakpoint; var breakpoint;
for (var i = 0; i < BREAKPOINTS.length; i++) { for (var i = 0; i < BREAKPOINTS.length; i++) {
if (BREAKPOINTS[i][0](date, now)) { if (BREAKPOINTS[i].test(date, now)) {
breakpoint = BREAKPOINTS[i]; breakpoint = BREAKPOINTS[i];
break; break;
} }
...@@ -116,7 +140,7 @@ function nextFuzzyUpdate(date) { ...@@ -116,7 +140,7 @@ function nextFuzzyUpdate(date) {
return null; return null;
} }
var secs = getBreakpoint(date, new Date())[2]; var secs = getBreakpoint(date, new Date()).nextUpdate;
if (secs === null) { if (secs === null) {
return null; return null;
...@@ -178,7 +202,7 @@ function toFuzzyString(date) { ...@@ -178,7 +202,7 @@ function toFuzzyString(date) {
if (!breakpoint) { if (!breakpoint) {
return ''; return '';
} }
return breakpoint[1](new Date(date), now); return breakpoint.format(new Date(date), now);
} }
module.exports = { module.exports = {
......
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