Skip Menu |

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

Report information
The Basics
Id: 67866
Status: open
Priority: 0/
Queue: DateTime-Format-Epoch

People
Owner: Nobody in particular
Requestors: m.nooning [...] comcast.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.13
Fixed in: (no value)



Subject: Wrong date being returned
For example, instead of 2011-04-30, I am get back 2052-08-27. The results are pasted after the __END__ statement in the attached code snippet. Windows XP Home SP3 Build 2600, X86-based, 32 bit. Time Zone: Eastern Daylight Time ActiveState Perl v5.12.2 on Windows XP Version 5.1.2600 Binary build 1202 [293621] $DateTime::VERSION 0.68 $DateTime::Format::Epoch::VERSION 0.13
Subject: test.pl
use DateTime; use DateTime::Format::Epoch; my $epoch = time(); print ("time() epoch is $epoch\n"); $dt = DateTime->from_epoch( epoch=> $epoch, time_zone => "America/New_York", ); print("DateTime Formatted yyyy-mm-dd is ", $dt->ymd('-'), "\n"); my $formatter = DateTime::Format::Epoch->new( epoch => $dt ); my $dt2 = $formatter->parse_datetime( $epoch ); print ("formatter->parse_datetime dt2 = ", $dt2, "\n"); $formatter->format_datetime($dt2); print ("formatter->parse_datetime given dt2: ", $formatter->format_datetime($dt2), "\n"); __END__ The results are pasted below. C:\>perl test.pl time() epoch is 1304196367 DateTime Formatted yyyy-mm-dd is 2011-04-30 formatter->parse_datetime dt2 = 2052-08-27T17:32:14 formatter->parse_datetime given dt2: 1304196367
On Sat Apr 30 17:00:08 2011, m.nooning@comcast.net wrote: Show quoted text
> For example, instead of 2011-04-30, I am get back 2052-08-27.
Show quoted text
> my $formatter = DateTime::Format::Epoch->new( epoch => $dt );
$dt here is start date. From documentation: "This datetime is the starting point of the day count". See http://search.cpan.org/perldoc?DateTime::Format::Epoch So you add 41 (years from 1970) to 2011. 2052 is correct. I guess documentation should be more clear here, so if you can provide better words, I'll modify documentation. -- Alexandr Ciornii, http://chorny.net
Subject: Re: [rt.cpan.org #67866] Wrong date being returned
Date: Mon, 02 May 2011 08:53:50 -0400
To: bug-DateTime-Format-Epoch [...] rt.cpan.org
From: Malcolm Nooning <m.nooning [...] comcast.net>
Naturally, care must be taken when reading the explanations to discern properly. Then there are the readers preset expectations. You know. The ones that automatically sway the interpretation of anything that is written. The module in question is a good case in point. I would have expected something of the form $current_parsed_date_and_time = $formatter->parse_datetime( $epoch ); to give back the answer assuming a start date of 1970-01-01T00:00:00Z. I think the solution is to add something that would jar the user's brain a bit. The first sentence of the description section reads: This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the number of seconds since a given epoch. I think the two sentences added below would be good. This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the number of seconds since a given epoch. Note that "a given epoch" does not imply the standard Unix epoch of 1970-01-01T00:00:00Z. The counting will start from whatever epoch you gave in the creation of the original DateTime object. By the way, I think "skip_leap_secondss" should be "skip_leap_seconds" Thank you.
From: m.nooning [...] comcast.net
Is there still an error here? Where did the extra five hours (T05) come from? Again, the answers are pasted after the __END__ statement in the code.
Subject: test.pl
use DateTime; use DateTime::Format::Epoch; my $epoch = time(); print ("time() epoch is $epoch\n"); my $dt = DateTime->new( time_zone => 'America/New_York', year => 1970, month => 1, day => 1, hour => 0, minute => 0, second => 0, ); print ("dt is $dt\n"); my $formatter = DateTime::Format::Epoch->new( epoch => $dt, unit => 'seconds', type => 'int', # or 'float', 'bigint' skip_leap_seconds => 1, start_at => 0, local_epoch => undef, ); my $formatter = DateTime::Format::Epoch->new( epoch => $dt, ); my $dt2 = $formatter->parse_datetime( epoch => $dt ); print ("First, formatter->parse_datetime dt2 = ", $dt2, "\n"); $formatter->format_datetime($dt2); print ("Second, formatter->parse_datetime given dt2: ", $formatter->format_datetime($dt2), "\n"); __END__ The results are pasted below. time() epoch is 1304343099 dt is 1970-01-01T00:00:00 First, formatter->parse_datetime dt2 = 1970-01-01T05:00:00 Second, formatter->parse_datetime given dt2: 0
On Mon 02 Mei 2011 09:38:36, m.nooning@comcast.net wrote: Show quoted text
> Is there still an error here? Where did the extra five hours (T05)
come Show quoted text
> from?
By default, epochs are converted to UTC. You specify an epoch of midnight, New York time, which is 05:00:00UTC. The output of parse_time is in UTC. If you want to keep the same timezone, change the local_epoch parameter to 1 in the definition of the formatter. By the way, this line: my $dt2 = $formatter->parse_datetime( epoch => $dt ); does not do what you think it does. parse_datetime takes a single parameter, which should be a number. In this case, the string "epoch" is interpreted as 0. You should get a warning about this if you run the test script with -w. Eugene
Subject: Re: [rt.cpan.org #67866] Wrong date being returned
Date: Mon, 02 May 2011 11:44:18 -0400
To: bug-DateTime-Format-Epoch [...] rt.cpan.org
From: Malcolm Nooning <m.nooning [...] comcast.net>
Excellent explanation. Thanks May I suggest some spoon feeding for people who do not normally work with date and time verbiage? The doc already uses 'America/Chicago' in one example, so, where the CPAN doc says: By default, the returned object will be in the UTC time zone. it might help to change it to: By default, the returned object will be in the UTC time zone. That means that, for example, if you specify time_zone => 'America/Chicago', there will be a 6 hour difference in the result. One more thing, the CPAN documentation for DateTime::Format::Epoch has parse_datetime($secs) but it also has ... parse_datetime accepts the same four element list ... Again, great module, and thank you very much for such quick responses. On 5/2/2011 10:34 AM, Eugene van der Pijll via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=67866> > > On Mon 02 Mei 2011 09:38:36, m.nooning@comcast.net wrote:
>> Is there still an error here? Where did the extra five hours (T05)
> come
>> from?
> By default, epochs are converted to UTC. You specify an epoch of > midnight, New York time, which is 05:00:00UTC. The output of parse_time > is in UTC. If you want to keep the same timezone, change the > local_epoch parameter to 1 in the definition of the formatter. > > By the way, this line: > my $dt2 = $formatter->parse_datetime( epoch => $dt ); > does not do what you think it does. > > parse_datetime takes a single parameter, which should be a number. In > this case, the string "epoch" is interpreted as 0. You should get a > warning about this if you run the test script with -w. > > Eugene > >