houseabsolute / DateTime-TimeZone

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

on unix systems, look for /etc/timezone first before /etc/localtime #3

Closed karenetheridge closed 9 years ago

karenetheridge commented 9 years ago

On ubuntu systems (Etch and later), /etc/localtime is a copy of /usr/share/zoneinfo/$zonefile, which means DateTime::TimeZone::Local::Unix spends a lot of time looking for the file that matches it, and it takes a LONG time (especially when done many times for a single page load!); whereas /etc/timezone also exists, and this is a simple file that contains the name of the timezone, so checking for this file first would be much faster.

ppisar commented 9 years ago

I don't like this change because standard library does not consider /etc/timezone at all. So if the /etc/timezone does not match /etc/localtime, this Perl code will not match the system.

karenetheridge commented 9 years ago

On Mon, Nov 03, 2014 at 03:46:45AM -0800, ppisar wrote:

I don't like this change because standard library does not consider /etc/timezone at all. So if the /etc/timezone does not match /etc/localtime, this Perl code will not match the system.

That sounds like a misconfigured system to me. The ubuntu documentation says to change /etc/timezone -- https://help.ubuntu.com/community/UbuntuTime#Using_the_Command_Line_.28terminal.29

ppisar commented 9 years ago

On Mon, Nov 03, 2014 at 09:32:19AM -0800, Karen Etheridge wrote:

On Mon, Nov 03, 2014 at 03:46:45AM -0800, ppisar wrote:

I don't like this change because standard library does not consider /etc/timezone at all. So if the /etc/timezone does not match /etc/localtime, this Perl code will not match the system.

That sounds like a misconfigured system to me. The ubuntu documentation says to change /etc/timezone -- https://help.ubuntu.com/community/UbuntuTime#Using_the_Command_Line_.28terminal.29

This is specific for Ubuntu.

Now read http://man7.org/linux/man-pages/man3/tzset.3.html how any application gets the time zone configuration on any POSIX system.

-- Petr

karenetheridge commented 9 years ago

On Mon, Nov 03, 2014 at 11:35:12PM -0800, ppisar wrote:

On Mon, Nov 03, 2014 at 09:32:19AM -0800, Karen Etheridge wrote:

On Mon, Nov 03, 2014 at 03:46:45AM -0800, ppisar wrote:

I don't like this change because standard library does not consider /etc/timezone at all. So if the /etc/timezone does not match /etc/localtime, this Perl code will not match the system.

That sounds like a misconfigured system to me. The ubuntu documentation says to change /etc/timezone -- https://help.ubuntu.com/community/UbuntuTime#Using_the_Command_Line_.28terminal.29

This is specific for Ubuntu.

Now read http://man7.org/linux/man-pages/man3/tzset.3.html how any application gets the time zone configuration on any POSIX system.

Do you have a suggestion for a solution?

ppisar commented 9 years ago

On Tue, Nov 04, 2014 at 08:44:57AM -0800, Karen Etheridge wrote:

On Mon, Nov 03, 2014 at 11:35:12PM -0800, ppisar wrote:

On Mon, Nov 03, 2014 at 09:32:19AM -0800, Karen Etheridge wrote:

On Mon, Nov 03, 2014 at 03:46:45AM -0800, ppisar wrote:

I don't like this change because standard library does not consider /etc/timezone at all. So if the /etc/timezone does not match /etc/localtime, this Perl code will not match the system.

That sounds like a misconfigured system to me. The ubuntu documentation says to change /etc/timezone -- https://help.ubuntu.com/community/UbuntuTime#Using_the_Command_Line_.28terminal.29

This is specific for Ubuntu.

Now read http://man7.org/linux/man-pages/man3/tzset.3.html how any application gets the time zone configuration on any POSIX system.

Do you have a suggestion for a solution?

Parse the /etc/localtime instead of guessing time zone name and then looking it up in the database bundled with the DateTime-TimeZone which slips behind the system database. Like in this patch https://rt.cpan.org/Public/Bug/Display.html?id=55029.

(The patch is just a last reason fall-back, but I'm going to remove the database from DateTime-TimeZone completly and make the DateTime::TimeZone::Tzfile approach the first default option (just after TZ environment variable).)

-- Petr

karenetheridge commented 9 years ago

It occurs to me that this bit of the process:

/etc/localtime is a copy of /usr/share/zoneinfo/$zonefile, which means DateTime::TimeZone::Local::Unix spends a lot of time looking for the file that matches it, and it takes a LONG time (especially when done many times for a single page load!)

...really should be only done once per process, and the result cached locally in DateTime::TimeZone::Local::Unix. There's no need to keep parsing the file multiple times.