Search code examples
perltimezonetemplate-toolkit

How can I switch timezones in Perl's Template::Plugin::Date?


I have a calendar on my website, generated in Perl using Template::Toolkit and Template::Plugin::Date.

It highlights the current day. I achieve this by iterating through all the dates (as I print the calendar) and comparing against the current date. Something like this:

[% IF cur_date == date.format(format = '%Y-%m-%d') %]
...
[% END %]

It all works well until someone in Australia looks at it. (They are in a different timezone to me and my server in the UK).

What's the best way to get Template::Plugin::Date to use a different time zone? It accepts a 'locale' parameter, but AFAIK this is only used for formatting.


Solution

  • For anything more than very simple dates, you should be using DateTime and/or Template::Plugin::DateTime.