EngineeringBug FixHabits
The Midnight Problem: Why Your Streak Looked Broken
feeldata Team·
TL;DR: We fixed a bug where users in different timezones saw incorrect "streak at risk" warnings.
What went wrong?
Our habit tracker shows a warning when you might lose your streak. The logic is simple: if you had a streak yesterday but didn't complete your habit, we warn you today.
The problem? We calculated "today" and "yesterday" using the server's clock, not yours.
# The bug
today = date.today() # Server time (UTC)
If our server runs in UTC and you live in Los Angeles (UTC-8), here's what happens at 11pm your time:
- Your perspective: It's still Monday evening. You have time to complete your habit.
- Server perspective: It's 7am Tuesday. Monday is "yesterday." You missed it!
Result: False "streak at risk" warnings.
The fix
We now read your timezone from your profile and calculate dates accordingly:
# The fix
user_tz = ZoneInfo(profile.timezone or "UTC")
now_local = datetime.now(timezone.utc).astimezone(user_tz)
today = now_local.date()
Three steps:
- Get your timezone setting (e.g., "America/Los_Angeles")
- Convert current UTC time to your local time
- Extract the date from that local time
Now "today" means today for you.
Lessons learned
- Always store timestamps in UTC
- Always convert to user's timezone for display and logic
- Time bugs are sneaky—they only appear for users far from your server's timezone
This fix is available now. Make sure your timezone is set correctly in your profile settings!