houseabsolute / DateTime-TimeZone

Time zone object base class and factory
https://metacpan.org/release/DateTime-TimeZone/
Other
9 stars 25 forks source link

offset_for_datetime is very slow for times in the (far) future. #42

Open Abigail opened 3 years ago

Abigail commented 3 years ago

This is very fast:

my $tz = DateTime::TimeZone -> new (name => 'Europe/Amsterdam');
my $dt = DateTime:: -> from_epoch  (epoch => time);   
my $x  = $tz -> offset_for_datetime ($dt);

taking only a millisecond or so.

Making a slight change:

my $tz = DateTime::TimeZone -> new (name => 'Europe/Amsterdam');
my $dt = DateTime:: -> from_epoch  (epoch => 1800 * time);   
my $x  = $tz -> offset_for_datetime ($dt);

and the code runs more than 3 minutes before it completes.

autarch commented 3 years ago

This is the same issue as https://github.com/houseabsolute/DateTime.pm/issues/90

One quick fix is to just use https://metacpan.org/release/DateTime-TimeZone-Tzfile for your zones instead. It's a bit less convenient since you have to pass a TZ object into the DateTime constructor. You could subclass DateTime to make it use the Tzfile class when given a zone name.