Make sure friendly date markers are reset at midnight

This commit is contained in:
Jérémie Astori 2017-04-22 00:06:07 -04:00
parent 648cfd12db
commit 5fabf2f61a
2 changed files with 21 additions and 1 deletions

View File

@ -3,6 +3,7 @@
// vendor libraries // vendor libraries
require("jquery-ui/ui/widgets/sortable"); require("jquery-ui/ui/widgets/sortable");
const $ = require("jquery"); const $ = require("jquery");
const moment = require("moment");
const Mousetrap = require("mousetrap"); const Mousetrap = require("mousetrap");
const URI = require("urijs"); const URI = require("urijs");
@ -1593,6 +1594,25 @@ $(function() {
} }
}); });
// Compute how many milliseconds are remaining until the next day starts
function msUntilNextDay() {
return moment().add(1, "day").startOf("day") - moment();
}
// Go through all Today/Yesterday date markers in the DOM and recompute their
// labels. When done, restart the timer for the next day.
function updateDateMarkers() {
$(".date-marker-text[data-label='Today'], .date-marker-text[data-label='Yesterday']")
.closest(".date-marker-container")
.each(function() {
$(this).replaceWith(templates.date_marker({msgDate: $(this).data("timestamp")}));
});
// This should always be 24h later but re-computing exact value just in case
setTimeout(updateDateMarkers, msUntilNextDay());
}
setTimeout(updateDateMarkers, msUntilNextDay());
// Only start opening socket.io connection after all events have been registered // Only start opening socket.io connection after all events have been registered
socket.open(); socket.open();

View File

@ -1,4 +1,4 @@
<div class="tooltipped tooltipped-s" aria-label="{{localedate msgDate}}"> <div class="date-marker-container tooltipped tooltipped-s" data-timestamp="{{msgDate}}" aria-label="{{localedate msgDate}}">
<div class="date-marker"> <div class="date-marker">
<span class="date-marker-text" data-label="{{friendlydate msgDate}}"></span> <span class="date-marker-text" data-label="{{friendlydate msgDate}}"></span>
</div> </div>