Commit 8f11738a authored by Sean Hammond's avatar Sean Hammond

Don't update timestamps > one day ago

If an annotation is more than one day old then it gets a timestamp like
"09 May". The next time this timestamp would change would be on
1 Jan 2017 when it would change to "09 May 2016". Rather than setting a
really long timer, just never live update "09 May"-format timestamps.

The case where Hypothesis is left open without reloading a page until
the end of the year, and the case where Hypothesis is opened close to
midnight on Dec 31st, are obscure enough to ignore.

If an annotation is not from the current year then it gets a timestamp
like "14 March 2015". The format of this timestamp will always be the
same, so don't set any timeout to update it.
parent fc4d0c15
......@@ -32,10 +32,10 @@ var FIXTURES_NEXT_FUZZY_UPDATE = [
[minute + 5, minute],
[3 * minute + 5, minute],
[4 * hour, hour],
[27 * hour, day],
[3 * day + 30 * minute, day],
[6 * month + 2 * day, 24 * day], // longer times are not supported
[8 * year, 24 * day] // by setTimout
[27 * hour, null],
[3 * day + 30 * minute, null],
[6 * month + 2 * day, null],
[8 * year, null]
];
describe('time', function () {
......@@ -155,6 +155,18 @@ describe('time', function () {
sandbox.clock.tick(minute * 1000);
assert.notCalled(callback);
});
it('does not set a timeout for dates > 24hrs ago', function() {
var date = new Date();
var ONE_DAY = day * 1000;
sandbox.clock.tick(10 * ONE_DAY);
var callback = sandbox.stub();
time.decayingInterval(date, callback);
sandbox.clock.tick(ONE_DAY * 2);
assert.notCalled(callback);
});
});
describe('.nextFuzzyUpdate', function () {
......
......@@ -92,8 +92,8 @@ var BREAKPOINTS = [
[lessThanOneMinuteAgo, nSec, 1],
[lessThanOneHourAgo, nMin, minute],
[lessThanOneDayAgo, nHr, hour],
[thisYear, dayAndMonth, month],
[function () {return true;}, dayAndMonthAndYear, year]
[thisYear, dayAndMonth, null],
[function () {return true;}, dayAndMonthAndYear, null]
];
function getBreakpoint(date, now) {
......@@ -145,6 +145,9 @@ function decayingInterval(date, callback) {
var timer;
var update = function () {
var fuzzyUpdate = nextFuzzyUpdate(date);
if (fuzzyUpdate === null) {
return;
}
var nextUpdate = (1000 * fuzzyUpdate) + 500;
timer = setTimeout(function () {
callback(date);
......
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