Hello,
I am writing a plugin that uses the timezone. Ikiwiki.pm defines the default timezone to :/etc/localtime
. The problem is that I do not know how to parse this.
In my code, I have lines like $now = DateTime->now(time_zone => $config{timezone});
or $thistime = DateTime->from_epoch(epoch=>$thistime, time_zone=>$config{timezone});
. They work well when timezone is something like Europe/Paris
, but with the default :/etc/localtime
, I get the error message The timezone ':/etc/localtime' is an invalid name.
Is there a way to automatically recognize both Europe/Paris
and :/etc/localtime
? Or should I add something like the following in my code?
if ($config{timezone} eq ":/etc/localtime") {
$config{timezone} = DateTime::TimeZone->new(name=>'local')->name();
}
Regards,
Louis
:/etc/localtime
is a glibc'ism, added to solve without timezone, excessive statting causes slowness. It means "read the contents or symlink destination of/etc/localtime
and use that as the active time zone".I would not recommend parsing that string, although you could.
ikiwiki sets the
TZ
environment variable to either$config{timezone}
or that default value during startup; so can't your plugin just use local time unconditionally, viatime_zone => 'local'
, without ever caring about which specific time zone that means?(For example, the standard
IkiWiki::formattime
useslocaltime($time)
which is basically a non-OO version ofDateTime->from_epoch(epoch => $time, time_zone => 'local')
.)Perfect! Thanks.
-- Louis