Skip Menu |

This queue is for tickets about the DateTime-Format-HTTP CPAN distribution.

Report information
The Basics
Id: 62332
Status: resolved
Priority: 0/
Queue: DateTime-Format-HTTP

People
Owner: Nobody in particular
Requestors: DOUGDUDE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in:
  • 0.35
  • 0.37
  • 0.38
  • 0.38_01
  • 0.39
Fixed in: (no value)



Subject: format_isoz does not change time zone
format_isoz doesn't actually change the time zone, because the DateTime object is cloned and then the new object is never assigned back to $dt. sub format_isoz { my ($self, $dt) = @_; $dt = DateTime->now unless defined $dt; # XXX: Line below "$dt = " was added to make it work as expected. $dt = $dt->clone->set_time_zone( 'UTC' ); sprintf("%04d-%02d-%02d %02d:%02d:%02dZ", $dt->year, $dt->month, $dt->day, $dt->hour, $dt->min, $dt->sec ); }
Hi DOUGDUDE, Thanks for the report. Could you supply a test as well so this bugfix will be covered by the testsuite? If you're familiar with Git you can clone the repository from GitHub (http://github.com/Htbaa/DateTime-Format-HTTP). A normal patch file would be fine too.
Sorry, I wasn't on a computer with git at the time. Attached is the patch.
Subject: 0001-Fix-issue-where-format_isoz-did-not-change-the-time-.patch
From 28d77c6e197d524525784c9f11343798a9eb337d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson <doug@somethingdoug.com> Date: Thu, 21 Oct 2010 13:20:09 -0400 Subject: [PATCH] Fix issue where format_isoz() did not change the time zone to UTC --- lib/DateTime/Format/HTTP.pm | 2 +- t/date.t | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/DateTime/Format/HTTP.pm b/lib/DateTime/Format/HTTP.pm index 0670927..bad6aca 100644 --- a/lib/DateTime/Format/HTTP.pm +++ b/lib/DateTime/Format/HTTP.pm @@ -91,7 +91,7 @@ sub format_isoz { my ($self, $dt) = @_; $dt = DateTime->now unless defined $dt; - $dt->clone->set_time_zone( 'UTC' ); + $dt = $dt->clone->set_time_zone( 'UTC' ); sprintf("%04d-%02d-%02d %02d:%02d:%02dZ", $dt->year, $dt->month, $dt->day, $dt->hour, $dt->min, $dt->sec diff --git a/t/date.t b/t/date.t index 3162249..b5a8f3f 100644 --- a/t/date.t +++ b/t/date.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; use lib 'inc'; -use Test::More tests => 116; +use Test::More tests => 118; use vars qw( $class ); BEGIN { @@ -171,3 +171,25 @@ for ($a, $b) { for ($az, $bz) { like( $_ => qr/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$/, "time2isoz($_)" ); } + +{ + # format_isoz must output date in UTC + my $eastern_date = DateTime->new( + year => 2010, + month => 10, + day => 21, + hour => 13, + minute => 8, + second => 23, + time_zone => 'America/New_York', + ); + + # Get the ISO "Z" format of the eastern zone date time + my $isoz = $class->format_isoz($eastern_date); + + # Get the actual UTC date time + my $utc = $eastern_date->clone->set_time_zone('UTC'); + + is($isoz, $class->format_isoz($utc), 'format_isoz converts to UTC time zone'); + is($eastern_date->time_zone->name, 'America/New_York', 'format_isoz does not modify input date\'s time zone'); +} -- 1.7.3.1.msysgit.0
Thanks for creating the patch. I'll apply it this weekend and will release it then.
I've applied your patch and submitted 0.40 to CPAN. It should be up soon.