1use strict; 2BEGIN { $^W = 1 } 3 4use Test::More tests => 10; 5use DateTime; 6use DateTime::Format::Epoch; 7 8my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); 9 10my $f = DateTime::Format::Epoch->new( epoch => $dt, unit => 'nanoseconds' ); 11my $f_m = DateTime::Format::Epoch->new( epoch => $dt, unit => 'milliseconds' ); 12my $f_mu = DateTime::Format::Epoch->new( epoch => $dt, unit => 'microseconds' ); 13my $f_d = DateTime::Format::Epoch->new( epoch => $dt, unit => 10 ); 14 15isa_ok($f, 'DateTime::Format::Epoch' ); 16 17is($f->format_datetime($dt) + 0, 0*1e9, 'Epoch = 0'); 18isa_ok($f->format_datetime($dt), 'Math::BigInt'); 19 20$dt->set( hour => 1 ); 21is($f->format_datetime($dt) + 0, 3600*1e9, 'Epoch + 1hour'); 22 23$dt->set( day => 2, hour => 0 ); 24is($f->format_datetime($dt) + 0, 24*3600*1e9, 'Epoch + 1day'); 25 26$dt = DateTime->new( year => 2003, month => 4, day => 27, 27 hour => 21, minute => 9, second => 57, 28 nanosecond => 8e8, time_zone => 'Europe/Amsterdam' ); 29 30like($f->format_datetime($dt), qr/^\+?1051470597800000000/, '"now"'); 31is($f_m->format_datetime($dt), 1051470597800, '"now" (milli)'); 32is($f_mu->format_datetime($dt), 1051470597800000, '"now" (micro)'); 33is($f_d->format_datetime($dt), 10514705978, '"now" (deci)'); 34 35$dt = DateTime->new( year => 1969, month => 12, day => 22 ); 36is($f->format_datetime($dt), -10*24*3600*1e9, 'Epoch - 10days'); 37