-
-
Save jasonleow/75bd025dc8bcb61943f650fa6628a71f to your computer and use it in GitHub Desktop.
Check streak
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
if(user.lastPost) { | |
let lastDate = new Date(JSON.parse(user.lastPost)) | |
lastDate.setHours(0, 0, 0) | |
lastDate.setMilliseconds(0) | |
lastDate.setMinutes(-(data.offset)) | |
let currentDate = new Date() | |
currentDate.setDate(postDate.getDate() - 1) | |
currentDate.setHours(0, 0, 0) | |
currentDate.setMilliseconds(0) | |
currentDate.setMinutes(-(data.offset)) | |
if (lastDate.getTime() === currentDate.getTime()) { | |
user.streak++ | |
} else if (lastDate < currentDate) { | |
user.streak = 1 | |
} | |
} else { | |
user.streak = 1 | |
} | |
if(user.topStreak) { | |
if(user.streak > user.topStreak) { | |
user.topStreak = user.streak | |
} | |
} else { | |
user.topStreak = 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment