[CDBI] Time::Piece behaviour on CDBI::MySQL

Karjala <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
Time::Piece has this functionality:

__PACKAGE__->autoinflate(dates => 'Time::Piece')

that translates dates from the database to Time::Piece and vice versa.

This module assumes that the times stored in the database are GMT times 
(as opposed to local times).

A problem thus occurs when the times stored in the MySQL database are 
local times.

The following problem, specifically: time differences ($t - $s) are 
wrong. This program produces a big negative number instead of a number 
close to 5 which would be expected (assume I live east of London):


$a = localtime;
$row->time($a);

sleep(5);

$s = $row->time;
$t = localtime;

print $t - $s;


A way to solve this problem might be for the CDBI::MySQL developers to 
set another parameter for the autoinflate method, that would tell the 
module whether the times stored in the database are local times or GMT.

[In general, a Time::Piece object is GMT iff $t->[10] == 0, and local if 
$t->[10] == 1]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.