Last active
December 30, 2015 16:17
-
-
Save johanbrook/12533ea1b900df6fa0d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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