use
lib File::Spec->catdir(dirname(abs_path($0)),
'lib'
);
my
$t
;
lives_ok {
$t
= Date::Easy::Datetime->new }
"basic ctor call"
;
isa_ok
$t
,
'Date::Easy::Datetime'
,
'ctor with no args'
;
generate_times_and_compare { Date::Easy::Datetime->new, now }
"default ctor matches now function"
;
generate_times_and_compare { Date::Easy::Datetime->new,
local
=>
time
}
"default ctor matches return from time()"
;
my
$FMT
=
'%Y%m%d%H%M%S'
;
my
@SEXTUPLE_ARGS
=
qw< 19940203103223 20010905134816 19980908170139 19691231235959 20360229000000 >
;
foreach
(
@SEXTUPLE_ARGS
)
{
my
@args
= /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/;
s/^0//
foreach
@args
;
$t
= Date::Easy::Datetime->new(
@args
);
is
$t
->strftime(
$FMT
),
$_
,
"successfully constructed (6args): $_"
;
}
foreach
(
"12/31/2009"
,
"2/29/2000 2:28:09PM"
,
"10/14/1066 09:00:00 GMT"
,
"10/26/1881 15:00:00 MST"
,
"3/31/1918 03:00:00 EDT"
)
{
my
$t
= parsedate(
$_
);
isnt
$t
,
undef
,
"sanity check: can parse $_"
;
my
$dt
= Date::Easy::Datetime->new(
$t
);
compare_times(
$dt
,
local
=>
$t
,
"successfully constructed (1arg): $_"
);
}
foreach
(
"12/31/2009"
,
"2/29/2000 2:28:09PM"
,
"10/14/1066 09:00:00 GMT"
,
"10/26/1881 15:00:00 MST"
,
"3/31/1918 03:00:00 EDT"
)
{
my
$t
= parsedate(
$_
,
GMT
=> 1);
isnt
$t
,
undef
,
"sanity check: can parse $_ (GMT)"
;
compare_times(Date::Easy::Datetime->new(
UTC
=>
$t
),
UTC
=>
$t
,
"successfully constructed (2arg UTC): $_"
);
compare_times(Date::Easy::Datetime->new(
GMT
=>
$t
),
GMT
=>
$t
,
"successfully constructed (2arg GMT): $_"
);
compare_times(Date::Easy::Datetime->new(
local
=>
$t
),
local
=>
$t
,
"successfully constructed (2arg local): $_"
);
}
foreach
(
@SEXTUPLE_ARGS
)
{
my
@args
= /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/;
s/^0//
foreach
@args
;
foreach
my
$l
(
qw< local GMT UTC >
)
{
my
@extra_args
=
$l
eq
'local'
? () : (
GMT
=> 1);
my
$secs
= str2time(
join
(
' '
,
join
(
'/'
,
@args
[0,1,2]),
join
(
':'
,
@args
[3,4,5])),
@extra_args
);
isnt
$secs
,
undef
,
"sanity check: can parse $_ ($l)"
;
compare_times(Date::Easy::Datetime->new(
$l
=>
@args
),
$l
=>
$secs
,
"successfully constructed (7args $l): $_"
);
}
}
my
@t
= Date::Easy::Datetime->new;
is
scalar
@t
, 1,
'ctor not returning multiple values in list context'
;
isa_ok
$t
[0],
'Date::Easy::Datetime'
,
'ctor in list context'
;
done_testing;