File: 102_format.t

package info (click to toggle)
libdatetime-format-epoch-perl 0.11-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 228 kB
  • ctags: 30
  • sloc: perl: 364; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 1,250 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use strict;
BEGIN { $^W = 1 }

use Test::More tests => 11;
use DateTime;
use DateTime::Format::Epoch::Unix;

my $f = DateTime::Format::Epoch::Unix->new();

isa_ok($f, 'DateTime::Format::Epoch::Unix' );

my $dt = DateTime->new( year  => 1970, month => 1, day   => 1 );
is($f->format_datetime($dt), 0, 'Epoch = 0');
is(DateTime::Format::Epoch::Unix->format_datetime($dt), 0, 'Epoch = 0');

$dt->set( hour => 1 );
is($f->format_datetime($dt), 3600, 'Epoch + 1hour');
is(DateTime::Format::Epoch::Unix->format_datetime($dt), 3600, 'Epoch + 1hour');

$dt->set( day => 2, hour => 0 );
is($f->format_datetime($dt), 24*3600, 'Epoch + 1day');
is(DateTime::Format::Epoch::Unix->format_datetime($dt), 24*3600, 'Epoch + 1day');

$dt = DateTime->new( year => 2003, month => 4, day => 27,
                     hour => 21, minute => 9, second => 57,
                     nanosecond => 8e8, time_zone => 'Europe/Amsterdam' );

is($f->format_datetime($dt), 1051470597, '"now"');
is(DateTime::Format::Epoch::Unix->format_datetime($dt), 1051470597, '"now"');

$dt = DateTime->new( year => 1969, month => 12, day => 22 );
is($f->format_datetime($dt), -10*24*3600, 'Epoch - 10days');
is(DateTime::Format::Epoch::Unix->format_datetime($dt), -10*24*3600, 'Epoch - 10days');