Wiki entry for final decisions regarding Timezones (DST et al)

Wiki entry for final decisions regarding Timezones (DST et al)

by John Papaioannou -
Number of replies: 5
Finding a way to solve the practical problems of implementing support for DST is a good iterative excercise in hard thinking. Maybe some of the hard core developers can contribute here by thinking a bit about the issues discussed in this Wiki entry and the possible alternatives? wink

Wiki entry on Timezones

Jon
Average of ratings: -
In reply to John Papaioannou

Re: Wiki entry for final decisions regarding Timezones (DST et al)

by Martín Langhoff -
I think I have a solution for the problem you are describing. For each Zone+DST entry in the table, have the FROM year encoded as timestamp as well. We can generate that timestamp at Olson import stage, as GMT timestamp of (local) 00:00:00 if 1st January of the "FROM" year. ("FROM" is the Olson field of the starting year).

So your first step in your time resolution functions is to say "SELECT id from mdl_timezones_bla WHERE from_timestamp < $timestamp AND name='$zonename' ORDER BY from_timestamp DESC LIMIT 1". That'll narrow down on the right rule in one hit.

The other thing you are talking about is memoizing, and I think it makes sense to add some memoizing abilities to these functions. I haven't seen any interesting memoizing features in PHP... Perl has a beautifullly easy to use Memoize module.
In reply to Martín Langhoff

Re: Wiki entry for final decisions regarding Timezones (DST et al)

by Martín Langhoff -
Damn! Moodle-format eats my code! The SQL was:

SELECT id from mdl_timezones_bla WHERE from_timestamp < $timestamp AND zonename = '$zonename' ORDER BY from_timestamp DESC LIMIT 1;

This will give you the relevant Zone+DST rule in one go, no recursion or infinite loops required.
In reply to John Papaioannou

Olson Parser notes

by Martín Langhoff -
the parser is now feature complete, the entry point is the olson_todst($file) function. The following notes apply:

- it's reporting errors as E_USER_NOTICE because we don't want to stop processing and we also want to be able to run from command line -- at least that's how I've been processing and comparing output between runs of different versions.

- it's starting in 1970, which means we compute the zone+rules current in 1970

- it's providing "from_timestamp" field which has the "from" (aka year) field into a (GMT) timestamp of the (local) start of that year. As I posted earlier in this thread, it's an attempt at  having enough info to select the right rule, but it may be in the wrong place.

- the "AT" field in the rules, which ends up in (de)activate_time will sometimes be negative, due to the conversion of wall or standard time to GMT. We need to be able to find a way to deal with it as it is, because we can't really fudge the other activate_* and deactivate_* fields.

- the *_index *_day fields still haven't been updated to the new scheme -- (Jon if you want to hack the parse_on function go for it!)

- the fields in the final nested array may still need changing to match the new table structure -- (Jon you are designing the new table, have you got the colnames you want?)

Here's a sample zone+rules entry:
[rule] => AQ
[gmtoff] => 600
[name] => Australia/Brisbane
[from] => 1971
[apply_offset] => 60
[activate_month] => 10
[activate_time] => 12:00
[activate_index] => -1
[activate_day] => 0
[deactivate_month] => 1
[deactivate_time] => 21:00
[deactivate_index] => 1
[deactivate_day] => -1
[from_timestamp] => 31572000

Bear in mind that if there aren't any DST rules, then things look like:

[rule] =>
[gmtoff] => 480
[name] => Australia/Perth
[from] => 1974
[from_timestamp] => 126259200
Average of ratings: Useful (1)
In reply to Martín Langhoff

Re: Olson Parser notes

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Excellent!  approve  Thank you!

Completely minor point - since we're changing the DST to a complete timezones list perhaps the function could be called timezone_from_olson() or some such ...
In reply to Martin Dougiamas

Re: Olson Parser notes

by Martín Langhoff -
Naturally. I haven't aligned the function & variable names in the code completely to the latest plans, partly because Jon knows them more than I do.