Time::Pieceの中身の紹介。
bless( [0,0,23,1,6,113,1,181,0,undef,1], 'Time::Piece' )
blessされた配列が入ってる。
配列の意味は
use constant 'c_sec' => 0;
use constant 'c_min' => 1;
use constant 'c_hour' => 2;
use constant 'c_mday' => 3;
use constant 'c_mon' => 4;
use constant 'c_year' => 5;
use constant 'c_wday' => 6;
use constant 'c_yday' => 7;
use constant 'c_isdst' => 8;
use constant 'c_epoch' => 9;
use constant 'c_islocal' => 10;
こんな感じ。
説明はいいよね?
で、困った話。
is_deeply($expected_time_piece,$got_time_piece);
とかして、同じ時間なのにコケる時があった。
エラー見たら。
以下な感じ。
bless( [0,0,23,1,6,113,1,181,0,undef,1], 'Time::Piece' )
bless( [0,0,23,1,6,113,1,181,0,1372687200,1], 'Time::Piece' )
片方にepochの値の所が入っていたんですね。
ちなみに、undefのモノは、timepieceのインスタンスを作成した直後の物で、
epochが入っている方は、なんかいろいろ処理した後のもの。
そこで、time_pieceのソース見たら。
sub epoch {
my $time = shift;
if (defined($time->[c_epoch])) {
return $time->[c_epoch];
}
else {
my $epoch = $time->[c_islocal] ?
timelocal(@{$time}[c_sec .. c_mon], $time->[c_year]+1900)
:
timegm(@{$time}[c_sec .. c_mon], $time->[c_year]+1900);
$time->[c_epoch] = $epoch;
return $epoch;
}
}
という感じで、epochを使ったあとだと値が入るようだ。
なので、undefが入っている方のインスタンスをepochしてからexpectedとして
テストしたら通ったというお話。