SweetByte13 / Diem

Habit Tracker
1 stars 0 forks source link

Research DateTime Occurrence Patterns #7

Closed zbb272 closed 1 month ago

zbb272 commented 1 month ago

Need to look into if there are any commonly used date time occurrence patterns we can use for how often habits repeat.

zbb272 commented 1 month ago

It seems the closest thing to an industry standard is iCalendar formatting. (https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html, https://www.kanzaki.com/docs/ical/rrule.html) It is supported by many (almost all) calendar applications (so if in the future we want to export data to a google calendar or something it should still work).

Python libraries: iCalendar https://pypi.org/project/icalendar/ (also https://pypi.org/project/recurring-ical-events/ in related projects) Javascript libraries: rrule https://github.com/jkbrzt/rrule (https://stackoverflow.com/questions/46422299/how-to-create-icalendar-recurrencerrule-event-parser)

See this site for example usage: https://exontrol.com/exicalendar.jsp?config=/js#calendar

In general I think the app should work as follows: when user logins succesfully, the app makes a request to backend endpoint to refresh/update habit instances. The backend then checks either: last habit occurance due_date, or if no previous occurrences exist the create date of the habit. and uses it as the start date. The backend then uses the start date and recurrence pattern to generate all HabitOccurances up to the Current DateTime.

The UI should display previous HabitOccurances based on the instances returned from the backend, future occurances based on the recurrence pattern.

This is for 2 reasons: it prevents the need for a service to run that will calculate a certain amount of future dates every day. This will only generate saved data for active users, and inactive users will not have HabitOccurances generated.

Required Database change: need to add createdDateTime to Habits.