Commit 68e9b81c authored by Sean Hammond's avatar Sean Hammond

Add "01 Jan" and "01 Jan 1970" datetime formats

These are used when the datetime in question is more than 24 hours ago
but still in the current year, and when it's not in the current year,
respectively. They replace a few different datestring formats that were
previously being used for datetimes in this range.
parent f530dd1b
...@@ -16,13 +16,13 @@ var FIXTURES_TO_FUZZY_STRING = [ ...@@ -16,13 +16,13 @@ var FIXTURES_TO_FUZZY_STRING = [
[3 * minute + 5, '3 min'], [3 * minute + 5, '3 min'],
[hour, '1 hr'], [hour, '1 hr'],
[4 * hour, '4 hr'], [4 * hour, '4 hr'],
[27 * hour, '1 days ago'], [27 * hour, '01 Jan'],
[3 * day + 30 * minute, '3 days ago'], [3 * day + 30 * minute, '01 Jan'],
[6 * month + 2 * day, '6 months ago'], [6 * month + 2 * day, '01 Jan'],
[1 * year, 'one year ago'], [1 * year, '01 Jan 1970'],
[1 * year + 2 * month, 'one year ago'], [1 * year + 2 * month, '01 Jan 1970'],
[2 * year, '2 years ago'], [2 * year, '01 Jan 1970'],
[8 * year, '8 years ago'] [8 * year, '01 Jan 1970']
]; ];
var FIXTURES_NEXT_FUZZY_UPDATE = [ var FIXTURES_NEXT_FUZZY_UPDATE = [
......
...@@ -22,20 +22,8 @@ function lessThanOneDayAgo(date, now) { ...@@ -22,20 +22,8 @@ function lessThanOneDayAgo(date, now) {
return ((now - date) < (24 * 60 * 60 * 1000)); return ((now - date) < (24 * 60 * 60 * 1000));
} }
function lessThanThirtyDaysAgo(date, now) { function thisYear(date, now) {
return ((now - date) < (30 * 24 * 60 * 60 * 1000)); return date.getFullYear() === now.getFullYear();
}
function lessThanOneYearAgo(date, now) {
// Here we approximate "one year" as being a calendar year and not a leap
// year: 365 days.
return ((now - date) < (365 * 24 * 60 * 60 * 1000));
}
function lessThanTwoYearsAgo(date, now) {
// Here we approximate "one year" as being a calendar year and not a leap
// year: 365 days.
return ((now - date) < (2 * 365 * 24 * 60 * 60 * 1000));
} }
function delta(date, now) { function delta(date, now) {
...@@ -54,16 +42,13 @@ function nHr(date, now) { ...@@ -54,16 +42,13 @@ function nHr(date, now) {
return '{} hr'.replace('{}', Math.floor(delta(date, now) / hour)); return '{} hr'.replace('{}', Math.floor(delta(date, now) / hour));
} }
function nDaysAgo(date, now) { function dayAndMonth(date) {
return '{} days ago'.replace('{}', Math.floor(delta(date, now) / day)); return date.toLocaleDateString(undefined, {day: '2-digit', month: 'short'});
}
function nMonthsAgo(date, now) {
return '{} months ago'.replace('{}', Math.floor(delta(date, now) / month));
} }
function nYearsAgo(date, now) { function dayAndMonthAndYear(date) {
return '{} years ago'.replace('{}', Math.floor(delta(date, now) / year)); return date.toLocaleDateString(
undefined, {day: '2-digit', month: 'short', year: 'numeric'});
} }
var BREAKPOINTS = [ var BREAKPOINTS = [
...@@ -71,10 +56,8 @@ var BREAKPOINTS = [ ...@@ -71,10 +56,8 @@ var BREAKPOINTS = [
[lessThanOneMinuteAgo, nSec, 1], [lessThanOneMinuteAgo, nSec, 1],
[lessThanOneHourAgo, nMin, minute], [lessThanOneHourAgo, nMin, minute],
[lessThanOneDayAgo, nHr, hour], [lessThanOneDayAgo, nHr, hour],
[lessThanThirtyDaysAgo, nDaysAgo, day], [thisYear, dayAndMonth, month],
[lessThanOneYearAgo, nMonthsAgo, month], [function () {return true;}, dayAndMonthAndYear, year]
[lessThanTwoYearsAgo, function () {return 'one year ago';}, year],
[function () {return true;}, nYearsAgo, year]
]; ];
function getBreakpoint(date, now) { function getBreakpoint(date, now) {
......
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