Building Streaks 🔥 - How?

Hi there,

I have a Habit App and I want to add streaks to my habits. Like Snapchat or like Duolingo. If the user completes the habit +1 on the streak. If he does not the streak goes to zero.

The problem is: checking the status of the streak.

Currently I am saving the “completed” dates as a list of texts (date:formatted as 24/07/2023) to each habit.

I am not sure how I can find out how long the current streak went - and it becomes even more complicated as I have different intervals (Daily, Weekly, Monthly, Yearly, Custom: user selects weekdays)

Maybe a possibility would be to just check the streak on the frontend (so have nothing in the database)?

Would be more than thankful for any hints on how to achieve this…

PS: obviously also open to make changes to the db

Why are you doing that? If you want to do anything to do with dates, then use dates, not texts.

But you probably don’t need to store every date… just the first and last of the streak.

When a user completes a task, check if the current date is more than 1 day since the existing end date of the streak.

If it’s not, then set the current date as the new streak end date.

If it is, then set the current date as the new streak start date.

1 Like

The app also contains a calendar and it comes in handy to check if the task should be displayed that day. I am storing every date so that the user can go back in the calendar to see when he did what (probably not even that important)

To save the start and end date is an idea.

What about other cycles (weekly and most of all Custom: where the user selects different days of the week)? They are saved in the database as numbers (for :extract day)

The app also contains a calendar and it comes in handy to check if the task should be displayed that day. I am storing every date so that the user can go back in the calendar to see when he did what (probably not even that important)

So just store the previous streaks somewhere (probably as a separate datatype would be best).

What about other cycles (weekly and most of all Custom: where the user selects different days of the week)? They are saved in the database as numbers (for :extract day)

It depends what you mean exactly, but the same concept should apply regardless of the timeframe.

What i mean is that there are habits, with custom cycles; e.g. Exercise every Monday, Wednesday, Friday.

—> After a user completes their first action, cancel, then reschedule an APi WF to reset the streak tomorrow at 23:59pm. This way, the user basically pushes back the “resetting” of their streak as long as they keep working out every day.

that could probably be a neat solution…