Last active
January 12, 2021 09:03
-
-
Save tharna/7f8a1dc66e1d4a6f29a5014929e6a183 to your computer and use it in GitHub Desktop.
Check streak
This file contains hidden or 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