Skip to content

Instantly share code, notes, and snippets.

@tharna
Last active January 12, 2021 09:03
Show Gist options
  • Save tharna/7f8a1dc66e1d4a6f29a5014929e6a183 to your computer and use it in GitHub Desktop.
Save tharna/7f8a1dc66e1d4a6f29a5014929e6a183 to your computer and use it in GitHub Desktop.
Check streak
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