Gossamer Forum
Home : Gossamer Threads Inc. : Discussion :

GT::Date Bug?

Quote Reply
GT::Date Bug?
I may be misunderstanding the workings of GT::Date in which case I apologize in advance, however in format_date() the code that parses the GMT offset is:

Code:
o => sub {
my $offset = date_gmt_offset();
return sprintf ("%+05d", int($offset / 3600) * 100 + int(($offset % 3600) /60))
}

The offset is retrieved from date_gmt_offset() which contains the following code:

Code:
sub date_gmt_offset {
# ----------------------------------------------------
# Returns the offset from local to gmtime in seconds.
# This can be a negative number.
#
my @lt = localtime;
unless (defined $GM_OFFSET and $lt[8] == $GM_OFFSET_DST) {
$GM_OFFSET = timegm(@lt) - timelocal(@lt);
$GM_OFFSET_DST = $lt[8];
}
return $GM_OFFSET;
}

Now the reason I think there is a bug in there is because if I have passed a custom epoch time into date_get(), for example....

Code:
date_get(time() + 7200);

...then the GMT offset is calculated using localtime(time()) and not my custom time, so you have:

timegm(@lt) # Epoch seconds to the current GMT
-minus-
timelocal(@lt) # Epoch seconds to local time.

..so the difference is +0000 in my case, but if I passed time() + 7200 to date_get then it should be +0200

Am I losing my mind or is that correct?