Period Types as time interval sequences #358
Unanswered
jbee
asked this question in
Specs & RFCs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
ATM periods and period types are pretending to work within any calendar system. The calendar used is a system setting (that can never change once used). This IMO is a confusion around the concept of time "buckets" (slicing up a continuous timeline into a sequence of intervals). A bucketing system such as "week of year" is very tightly connected to one calendar system. Other calendars might have a similar concept that is also similarly named but these would be 2 distinct sequences that have nothing in common other than the terms we use to refer to them. Specifically any ISO conform period is always a Gregorian calendar period. In contrast a weekly period in the traditional Chinese calendar would have 10 day weeks in a variable length Year. This is an entirely different sequence to the ISO weeks. It does not make sense for these 2 to share any code or for data of the two to be compared to each other. Attempting to do so has lead to the very complicated and fragile date related code in DHIS2 where the attempt to make it "multi-calendar ready" has moved it to a state that is inconsistent, incorrect and incomplete and very hard to reason about.
The complication is further stressed by the need for custom period types. These are essentially sequences that do not follow a calendar but a lookup table of decided dates and names for the intervals they hold. A classic example would be a school year with Spring term, Autumn term and alike.
Last but not least, the idea that all periods in a DHIS2 system must follow a single calendar is wrong on many levels. It is an unnecessary limitation, source of great confusion and risk to break the data. Imagine a country now using non-ISO weeks but entering a transition phase to join the ISO world. Such a system would clearly have multiple weekly (start Monday) types. The non-ISO one for old existing data and ISO weeks for new data. This cannot be solved in a system where one calendar rules them all.
In contrast, it is easy to see that data points entered for time intervals belonging to a specific calendar should never change their semantics. The semantics implied by the type and its implied calendar is what anchors the data in time.
Solution Outline
Custom Period Types
A custom type is essentially a lookup table with the columns
The main challenge with custom period types is to make sure the ID string is unique and does not collide with the identification of other period types. At the same time it should be as readable and self explanatory as possible. It seems reasonable to limit custom periods to such sequences that split a year into intervals. Meaning they also can follow the general pattern
YYYY$?where$marks the infix that is unique for a period type. For example, for a school term type, the infix may beST, a term can be written as2026ST1,2026ST2and so forth. Like in this example, digits can follow the infix.Prototype
Timestamps
As the prototype indicates periods and period types or sequences can and should work without a link to an absolute timeline (like a timestamp would provide). They track days independent of when exactly such a day would have started on an absolute timeline somewhere. The reason is simply that the start of day on a absolute timeline is always linked to a place or timezone. This confuses and complicates the world or time intervals with the world of time-zones. Such complication is entirely unnecessary. Instead everything can be described in days since a fix-point. The idea is similar to a timestamp except that the fix-point is a local date without time zone.
This also has the advantage of being able to calculate the length of a period in days without understanding the calendar. It is simply the difference between the last and the first day fix-point offset. In addition it is trivial for most types to advance the next interval in the sequence.
Ideally DHIS2 would have used such a model for periods from the beginning but unfortunately we have to deal with the past of start and end dates being stored as timestamps in the database. While a big task, it is an option to also refactor the database. More realistically we maintain timestamps by making them absolute assuming the servers time-zone to compute the corresponding timestamps.
Time-zones
By its nature aggregate numbers for a span of days does not have to deal with time-zones. While it did matter for the counting to consider when days start and end once the number for a day or a span of days is counted and then reported to DHIS2 the system does not have to care about absolute time. Users will usually select days with a date picker specifying the day or day span independent of time-zones. There might be special cases where the API does not require the user to give a day but will implicitly assume that the current one is to pick. This is where time-zones matter when it is determined what the current day is in the calendar that is implied in a period sequence. Maybe we can do without such a feature. It is unclear if such a period creation is used beyond tests.
Beta Was this translation helpful? Give feedback.
All reactions