Skip to content

Instantly share code, notes, and snippets.

@jasonleow
Forked from tharna/streak.js
Created January 12, 2021 09:03
Show Gist options
  • Save jasonleow/75bd025dc8bcb61943f650fa6628a71f to your computer and use it in GitHub Desktop.
Save jasonleow/75bd025dc8bcb61943f650fa6628a71f 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