Skip Menu |

This queue is for tickets about the Date-Manip CPAN distribution.

Report information
The Basics
Id: 94973
Status: resolved
Priority: 0/
Queue: Date-Manip

People
Owner: Nobody in particular
Requestors: et [...] libersoft.it
Cc:
AdminCc:

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



Subject: Printf '%o' and CEST: bug or misunderstanding?
Date: Wed, 23 Apr 2014 22:13:39 +0200
To: bug-Date-Manip [...] rt.cpan.org
From: Emanuele Tomasi <et [...] libersoft.it>
Date::Manip: v6.43 Perl: v5.18.1 This script: --- use Date::Manip; $date_str = '2014-03-31 22:00:00 GMT'; $date = new Date::Manip::Date; $date->config("tz","CEST"); $date->parse($date_str); $tm_localtime = $date->printf('%o'); $tm_gmt = $date->printf('%s'); $time_diff_hours = ($tm_localtime - $tm_gmt) / 3600; print $time_diff_hours . ' hours'; --- Returns "1 hours". But, the difference between CEST and GMT is 2 hours. What it's wrong? Note: I'm in Italy and today (2014-04-23) we are GMT+2 (CEST). Best regards, Emanuele -- Emanuele Tomasi <et@libersoft.it> Libersoft Srl - Linux e software libero Via Mario Giuntini, 25 - int. 34 - 56021 Navacchio - Cascina (PI) tel: +39 050 754737 fax: +39 050 754738
You're misunderstanding what you're looking at. You've got a date that you parsed ($date_str)... and it's fixed. Then, you compare that date to two different dates in the past: %s: 1970-01-01 00:00:00 GMT and %o: 1970-01-01 00:00:00 CET (because from 1945 to 1977, CEST did not do time changes, and spent the entire time in CET) and those two dates are 1 hour apart.
Subject: Re: [rt.cpan.org #94973] Printf '%o' and CEST: bug or misunderstanding?
Date: Fri, 25 Apr 2014 21:39:01 +0200
To: bug-Date-Manip [...] rt.cpan.org
From: Emanuele Tomasi <et [...] libersoft.it>
Thank you for your reply. What I'm searching are the seconds UTC from 1/1/1970 for a date, ignoring his time zone. I think this script works fine: --- use Date::Manip; $date_str = '2014-04-01 00:00:00'; $date = new Date::Manip::Date; $date->parse($date_str); $offset = $date->printf('%N'); ($h, $m, $s) = split(':', $offset); $sec_gmt = $date->printf('%s'); $sec_gmt += ($h * 3600 + $m * 60 + $s); print $sec_gmt; --- His output is: 1396310400 and: --- $> date -u --date='@1396310400' mar 1 apr 2014, 00.00.00, UTC --- What do you thing about? Best regards, Emanuele -- Emanuele Tomasi <et@libersoft.it> Libersoft Srl - Linux e software libero Via Mario Giuntini, 25 - int. 34 - 56021 Navacchio - Cascina (PI) tel: +39 050 754737 fax: +39 050 754738
How can you "ignore a timezone"? If you want to know the number of seconds since 1970-01-01 for a date, you have to know: what timezone is 1970-01-01 what timezone is the date you're interested in If you're going to ignore timezones, then you don't want an accurate number. If you really only want an estimate, then use Date::Manip::Base::secs_since_1970 .
Subject: Re: [rt.cpan.org #94973] Printf '%o' and CEST: bug or misunderstanding?
Date: Fri, 25 Apr 2014 23:42:05 +0200
To: bug-Date-Manip [...] rt.cpan.org
From: Emanuele Tomasi <et [...] libersoft.it>
My problem is that this script: --- use Date::Manip; use Mail::IMAPClient; $date_str = '2014-04-01 00:00:00'; $date = new Date::Manip::Date($date_str); $sec_gmt = $date->printf('%s'); $imap = new Mail::IMAPClient; print $imap->Rfc2060_date($sec_gmt); --- Prints "31-Mar-2014" instead of "01-Apr-2014". Emanuele
Subject: Re: [rt.cpan.org #94973] Printf '%o' and CEST: bug or misunderstanding?
Date: Mon, 28 Apr 2014 23:17:12 +0200
To: bug-Date-Manip [...] rt.cpan.org
From: Emanuele Tomasi <et [...] libersoft.it>
Ok, latest email. This script work fine: --- use Date::Manip; use Mail::IMAPClient; $date_str = '2014-04-01 00:00:00 +05:45:00'; $date = new Date::Manip::Date($date_str); # Calculating offset in seconds $offset = $date->printf('%N'); ($offset_h, $offset_m, $offset_s) = split(':', $offset); $offset_sign = substr($offset, 0, 1) . 1; $offset_h = substr($offset_h, 1); $offset_secs = $offset_sign * ($offset_h * 3600 + $offset_m * 60 + $offset_s); # These are the seconds for "2014-04-01 00:00:00 UTC" $secs_gmt = $date->printf('%s') + $offset_secs; $imap = new Mail::IMAPClient(); print $secs_gmt . ' ' . $imap->Rfc2060_date($secs_gmt); --- Its output is: 1396310400 01-Apr-2014 And: $> date -u --date='@1396310400' mar 1 apr 2014, 00.00.00, UTC Exactly what I'm searching for. Best regards, Emanuele