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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#!/usr/bin/perl
# Main testing for Time::Tiny
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use Test::More tests => 15;
use Time::Tiny ();
#####################################################################
# Basic test
SCOPE: {
my $tiny = Time::Tiny->new(
hour => 1,
minute => 2,
second => 3,
);
isa_ok( $tiny, 'Time::Tiny' );
is( $tiny->hour, '1', '->hour ok' );
is( $tiny->minute, 2, '->minute ok' );
is( $tiny->second, 3, '->second ok' );
is( $tiny->as_string, '01:02:03', '->as_string ok' );
is( "$tiny", '01:02:03', 'Stringification ok' );
is_deeply(
Time::Tiny->from_string( $tiny->as_string ),
$tiny, '->from_string ok',
);
my $now = Time::Tiny->now;
isa_ok( $now, 'Time::Tiny' );
}
#####################################################################
# DateTime Testing
SKIP: {
# Do we have DateTime
eval { require DateTime };
skip( "Skipping DateTime tests (not installed)", 7 ) if $@;
# Create a normal date
my $date = Time::Tiny->new(
hour => 1,
minute => 2,
second => 3,
);
isa_ok( $date, 'Time::Tiny' );
# Expand to a DateTime
my $dt = $date->DateTime;
isa_ok( $dt, 'DateTime' );
# DateTime::Locale version 1.00 changes "C" to "en-US-POSIX".
my $expected = eval { DateTime::Locale->VERSION(1) } ? "en-US-POSIX" : "C";
is( $dt->locale->id, $expected, '->locale ok' );
is( $dt->time_zone->name, 'floating', '->timezone ok' );
# Compare accessor results
is( $date->hour, $dt->hour, '->year matches' );
is( $date->minute, $dt->minute, '->month matches' );
is( $date->second, $dt->second, '->day matches' );
}
|