[Templates] [PATCH] Make Date.pm return in GMT
Keith G. Murphy
keithmur@mindspring.com
Fri, 15 Mar 2002 16:50:23 -0600
This is a multi-part message in MIME format.
--------------750F73A336542154756CC92A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This came up in my own work, so I thought it might be of use to the
world at large.
Adds a parameter to date.format to force output in GMT (only in the
seconds-since-epoch input case). Just uses gmtime instead of localtime.
Real simple patch, but worthwhile for me.
--------------750F73A336542154756CC92A
Content-Type: text/plain; charset=us-ascii;
name="Date.pm.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Date.pm.diff"
66d65
< # format($time, $format, $locale, $gmt_flag)
70,75c69,73
< # (or the current system time if unspecified) using the $format, $locale,
< # and $gmt values specified as arguments or internal values set defined
< # at construction time). Specifying a Perl-true value for $gmt will
< # override the local time zone and force the output to be for GMT.
< # Any or all of the arguments may be specified as named parameters which
< # get passed as a hash array reference as the final argument.
---
> # (or the current system time if unspecified) using the $format and
> # $locale values specified as arguments or internal values set defined
> # at construction time). Any or all of the arguments may be specified
> # as named parameters which get passed as a hash array reference as
> # the final argument.
87,88d84
< my $gmt = @_ ? shift(@_)
< : ($params->{ gmt } || $self->{ gmt });
93,97c89
< my $convfunc = &localtime;
< if ($gmt) {
< $convfunc = &gmtime;
< }
< @date = (&$convfunc($time))[0..6];
---
> @date = (localtime($time))[0..6];
263,271d254
< A fourth parameter allows you to force output in GMT, in the case of
< seconds-since-the-epoch input:
<
< [% date.format(filemod, '%d-%b-%Y', 'en_GB', 1) %]
<
< Note that in this case, if the local time is not GMT, then also specifying
< '%Z' (time zone) in the format parameter will lead to an extremely
< misleading result.
<
279d261
< [% date.format(mytime, format => '%H:%M:%S', gmt => 1) %]
--------------750F73A336542154756CC92A--