Skip to content

Instantly share code, notes, and snippets.

@johanbrook
Last active December 30, 2015 16:17
Show Gist options
  • Save johanbrook/12533ea1b900df6fa0d8 to your computer and use it in GitHub Desktop.
Save johanbrook/12533ea1b900df6fa0d8 to your computer and use it in GitHub Desktop.
var isSameDay = function (thisEntry, lastEntry) {
var endTime = moment('6:00am', 'h:mma');
if (lastEntry.isSame(thisEntry, 'day')) {
// Same day, but time has passed 6am since last click, in other words: new day
return !(thisEntry.isAfter(endTime) && lastEntry.isBefore(endTime));
} else if (lastEntry.isSame(thisEntry.subtract(1, 'days'))) {
// Last entry was yesterday, but after 6am, and this entry is before 6am, therefore within the same night
return thisEntry.isBefore(endTime) && lastEntry.isAfter(endTime);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment