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 = [
[3 * minute + 5, '3 min'],
[hour, '1 hr'],
[4 * hour, '4 hr'],
[27 * hour, '1 days ago'],
[3 * day + 30 * minute, '3 days ago'],
[6 * month + 2 * day, '6 months ago'],
[1 * year, 'one year ago'],
[1 * year + 2 * month, 'one year ago'],
[2 * year, '2 years ago'],
[8 * year, '8 years ago']
[27 * hour, '01 Jan'],
[3 * day + 30 * minute, '01 Jan'],
[6 * month + 2 * day, '01 Jan'],
[1 * year, '01 Jan 1970'],
[1 * year + 2 * month, '01 Jan 1970'],
[2 * year, '01 Jan 1970'],
[8 * year, '01 Jan 1970']
];
var FIXTURES_NEXT_FUZZY_UPDATE = [
......
......@@ -22,20 +22,8 @@ function lessThanOneDayAgo(date, now) {
return ((now - date) < (24 * 60 * 60 * 1000));
}
function lessThanThirtyDaysAgo(date, now) {
return ((now - date) < (30 * 24 * 60 * 60 * 1000));
}
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 thisYear(date, now) {
return date.getFullYear() === now.getFullYear();
}
function delta(date, now) {
......@@ -54,16 +42,13 @@ function nHr(date, now) {
return '{} hr'.replace('{}', Math.floor(delta(date, now) / hour));
}
function nDaysAgo(date, now) {
return '{} days ago'.replace('{}', Math.floor(delta(date, now) / day));
}
function nMonthsAgo(date, now) {
return '{} months ago'.replace('{}', Math.floor(delta(date, now) / month));
function dayAndMonth(date) {
return date.toLocaleDateString(undefined, {day: '2-digit', month: 'short'});
}
function nYearsAgo(date, now) {
return '{} years ago'.replace('{}', Math.floor(delta(date, now) / year));
function dayAndMonthAndYear(date) {
return date.toLocaleDateString(
undefined, {day: '2-digit', month: 'short', year: 'numeric'});
}
var BREAKPOINTS = [
......@@ -71,10 +56,8 @@ var BREAKPOINTS = [
[lessThanOneMinuteAgo, nSec, 1],
[lessThanOneHourAgo, nMin, minute],
[lessThanOneDayAgo, nHr, hour],
[lessThanThirtyDaysAgo, nDaysAgo, day],
[lessThanOneYearAgo, nMonthsAgo, month],
[lessThanTwoYearsAgo, function () {return 'one year ago';}, year],
[function () {return true;}, nYearsAgo, year]
[thisYear, dayAndMonth, month],
[function () {return true;}, dayAndMonthAndYear, year]
];
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