Not a bug, IMHO.

Below example proofs that the format you use to output time does not support 
timezone.
So "current time" looks different.

=========
$ cat T1.pl
use Time::Piece;
$time1 = localtime;
print $time1, "\n";
$time2 = gmtime;
print $time2, "\n";

$ perl T1.pl 
Mon Oct 14 01:13:52 2013
Sun Oct 13 21:13:52 2013
=========

And your original example can be fixed by specifying timezone in time
that you parse.

=========
$ cat T2.pl
use Time::Local;
use Time::Piece;

$time_now = localtime; # first time is specified by localtime
$time_future = Time::Piece->strptime("2013-10-14 01:16:00 +0400", "%Y-%m-%d 
%H:%M:%S %z");
print "Now it is $time_now\n";
print "We are going on holiday at $time_future\n";
$diff = $time_future - $time_now;
print "Remaining: $diff\n";

$ perl T1.pl 
Now it is Mon Oct 14 01:16:44 2013
We are going on holiday at Sun Oct 13 21:16:00 2013
Remaining: -44
=========

(i.e. "Mon Oct 14 01:16:44 2013" differs from "2013-10-14 01:16:00
+0400" by 44 seconds)

Also, if you replace "localtime" in T2 with "gmtime" you'll get same
difference.

So whole issue is that you parsed wrong time, Time::Piece interpreted it
as GMT time.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1190421

Title:
  perl converts localtime into gmt before subtraction

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/perl/+bug/1190421/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to