I have reward system where users can check in and get points. I want to make a streak system where if you check in 7 days in a row, you get extra points. It’s counted from the current day, and if you miss any day in the past week you don’t get extra points. It should then reset(delete entries?).
I can’t get the code to work. Can somebody help me? I appreciate it.
If there is logic already preventing duplicate “check-ins” then you could do this:
Get the user’s check-ins sorted by date then check the 7th item’s date is greater than the date 8 days ago.
Search for check-ins item #7's Date > Currentdate/time - 8d
You might need to fiddle with that a bit depending on how accurate you want the check-in rules to be.
The difficulty is preventing users from checking in more than once a day, yet preventing them from being pushed back further and further in the day.
So you either want to prevent them from checking in for 16 hours rather than 24. Or keep track of only the calendar date that they check in to prevent unhappy customers trying to check in 1 or 2 hours before they should be allowed to.
My suggestion would be to do both kinda.
I’d let the user check in “daily” every 16 hours. Just prevent user from checking in if last checkin was 16h or sooner.
I’d check eligibility by checking if there are 7 checkins in past 7.5 or 8 days. Depending on how accurate you want it to be. If you’re giving away a car you might want it to be perfect. If it’s a video game I’d just make it simple and people happy and give them a bit of wiggle room and check the past 8 days.
Imagine you check in at work at 9:00 every morning but can’t check in again for 24 hours exactly. So the first day you check in at 9:00. The second day you try to check in at 9:00 but it does not let you. Then you notice the clock goes to 9:01 and you check in. The next day it only lets you check in after 9:01 and you check in at 9:06. This quickly snowballs to you checking in at 3 something the next week because you can’t ever catch up.
Thanks for your answer, it worked! I don’t think the code is pushing them back though. My code rounds all the dates down and just compares it to see if it has been checked in today, which probably resets by itself.
Okay cool. Yeah if it just checks the date it won’t push back. Glad it works!