Subject: | Template::Plugin::Date won't format %z |
Template::Plugin::Date::format() calls localtime() or gmtime() but only sets @date to the first 7 values (line 97):
@date = (localtime($time))[0..6];
POSIX::strftime() defaults isdst (10th field) to -1:
strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
When glibc's strftime() function is called, it will ignore attempting to calculate the GMT offset when tm_isdst is < 0:
case L_('z'):
if (tp->tm_isdst < 0)
break;
Example:
perl -MPOSIX -e 'print POSIX::strftime("%F,%z\n", 59, 45, 12, 5, 0, 116, 2)'
2016-01-05,
perl -MPOSIX -e 'print POSIX::strftime("%F,%z\n", 59, 45, 12, 5, 0, 116, 2, 4, 0)'
2016-01-05,-0600
Patch extends @date to include all fields (0..8) from localtime()/gmtime() which are passed onto POSIX::strftime()
Subject: | PluginDate-strftime-gets-all-parameters.patch |
Template::Plugin::Date::format() calls localtime() or gmtime() but only sets @date to the first 7 values (line 97):
@date = (localtime($time))[0..6];
POSIX::strftime() defaults isdst (10th field) to -1:
strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
When glibc's strftime() function is called, it will ignore attempting to calculate the GMT offset when tm_isdst is <0:
case L_('z'):
if (tp->tm_isdst < 0)
break;
Example:
perl -MPOSIX -e 'print POSIX::strftime("%F,%z\n", 59, 45, 12, 5, 0, 116, 2)'
2016-01-05,
perl -MPOSIX -e 'print POSIX::strftime("%F,%z\n", 59, 45, 12, 5, 0, 116, 2, 4, 0)'
2016-01-05,-0600
Patch extends @date to include all fields (0..8) from localtime()/gmtime() which are passed onto POSIX::strftime()
Signed-off-by: Luke Suchocki <perl@lukiepoo.com>
diff -urp a/lib/Template/Plugin/Date.pm b/lib/Template/Plugin/Date.pm
--- a/lib/Template/Plugin/Date.pm 2016-01-05 14:34:15.937824132 -0600
+++ b/lib/Template/Plugin/Date.pm 2016-01-05 14:37:26.668107733 -0600
@@ -91,10 +91,10 @@ sub format {
if ($time =~ /^-?\d+$/) {
# $time is now in seconds since epoch
if ($gmt) {
- @date = (gmtime($time))[0..6];
+ @date = (gmtime($time))[0..8];
}
else {
- @date = (localtime($time))[0..6];
+ @date = (localtime($time))[0..8];
}
}
else {