#!/usr/bin/perl -w
BEGIN
{
eval
"use DateTime::Format::Strptime 1.0400"
;
if
($@)
{
plan
skip_all
=>
"DateTime::Format::Strptime 1.0400+ not installed"
;
}
plan
tests
=> 11;
}
my
$formatter
=
DateTime::Format::Strptime->new(
pattern
=>
'%Y%m%d %T'
,
locale
=>
'en_US'
,
);
my
$dt
= DateTimeX::Lite->from_epoch(
epoch
=>
time
(),
formatter
=>
$formatter
);
ok(
$dt
,
"Constructor (from_epoch) : $@"
);
$dt
=
eval
{ DateTimeX::Lite->new(
year
=> 2004,
month
=> 9,
day
=> 2,
hour
=> 13,
minute
=> 23,
second
=> 34,
formatter
=>
$formatter
) };
ok(
$dt
,
"Construtor (new) : $@"
);
$dt
=
eval
{ DateTimeX::Lite->from_object(
object
=>
$dt
,
formatter
=>
$formatter
) };
ok(
$dt
,
"Constructor (from_object) : $@"
);
is(
$dt
->formatter,
$formatter
,
"check from_object copies formatter"
);
is(
$dt
->_stringify_overload(),
'20040902 13:23:34'
,
'Format datetime'
);
is(
$dt
->_stringify_overload,
"$dt"
,
"Stringification (with formatter)"
);
$dt
->set(
hour
=> 3 );
is(
$dt
->_stringify_overload,
'20040902 03:23:34'
,
'formatter is preserved after set()'
);
$dt
->
truncate
(
to
=>
'minute'
);
is(
$dt
->_stringify_overload,
'20040902 03:23:00'
,
'formatter is preserved after truncate()'
);
$dt
->set_formatter(
undef
);
is(
$dt
->_stringify_overload(),
$dt
->iso8601,
'Default iso8601 works'
);
is(
$dt
->_stringify_overload,
"$dt"
,
"Stringification (no formatter -> format_datetime)"
);
is(
$dt
->iso8601,
"$dt"
,
"Stringification (no formatter -> iso8601)"
);