Lines 5-11
use DateTime;
Link Here
|
5 |
use DateTime::TimeZone; |
5 |
use DateTime::TimeZone; |
6 |
|
6 |
|
7 |
use C4::Context; |
7 |
use C4::Context; |
8 |
use Test::More tests => 30; |
8 |
use Test::More tests => 31; |
9 |
|
9 |
|
10 |
BEGIN { use_ok('Koha::DateUtils'); } |
10 |
BEGIN { use_ok('Koha::DateUtils'); } |
11 |
|
11 |
|
Lines 23-62
cmp_ok( $dt->ymd(), 'eq', $testdate_iso, 'Returned object matches input' );
Link Here
|
23 |
$dt->set_hour(12); |
23 |
$dt->set_hour(12); |
24 |
$dt->set_minute(0); |
24 |
$dt->set_minute(0); |
25 |
|
25 |
|
26 |
my $date_string = output_pref( $dt, 'iso', '24hr' ); |
26 |
my $date_string; |
|
|
27 |
|
28 |
my $dateformat = C4::Context->preference('dateformat'); |
29 |
cmp_ok output_pref({ dt => $dt, dateformat => $dateformat }), |
30 |
'eq', |
31 |
output_pref($dt), |
32 |
'output_pref gives an hashref or a dt'; |
33 |
|
34 |
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '24hr' }); |
27 |
cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output'; |
35 |
cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output'; |
28 |
|
36 |
|
29 |
$date_string = output_pref( $dt, 'iso', '12hr' ); |
37 |
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '12hr' }); |
30 |
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr'; |
38 |
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr'; |
31 |
|
39 |
|
32 |
# "notime" doesn't actually mean anything in this context, but we |
40 |
# "notime" doesn't actually mean anything in this context, but we |
33 |
# can't pass undef or output_pref will try to access the database |
41 |
# can't pass undef or output_pref will try to access the database |
34 |
$date_string = output_pref( $dt, 'iso', 'notime', 1 ); |
42 |
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => 'notime', dateonly => 1 }); |
35 |
cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)'; |
43 |
cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)'; |
36 |
|
44 |
|
37 |
$date_string = output_pref( $dt, 'us', '24hr' ); |
45 |
$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '24hr' }); |
38 |
cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output'; |
46 |
cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output'; |
39 |
|
47 |
|
40 |
$date_string = output_pref( $dt, 'us', '12hr' ); |
48 |
$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '12hr' }); |
41 |
cmp_ok $date_string, 'eq', '06/16/2011 12:00 PM', 'us output 12hr'; |
49 |
cmp_ok $date_string, 'eq', '06/16/2011 12:00 PM', 'us output 12hr'; |
42 |
|
50 |
|
43 |
$date_string = output_pref( $dt, 'us', 'notime', 1 ); |
51 |
$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => 'notime', dateonly => 1 }); |
44 |
cmp_ok $date_string, 'eq', '06/16/2011', 'us output (date only)'; |
52 |
cmp_ok $date_string, 'eq', '06/16/2011', 'us output (date only)'; |
45 |
|
53 |
|
46 |
# metric should return the French Revolutionary Calendar Really |
54 |
# metric should return the French Revolutionary Calendar Really |
47 |
$date_string = output_pref( $dt, 'metric', '24hr' ); |
55 |
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' }); |
48 |
cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output'; |
56 |
cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output'; |
49 |
|
57 |
|
50 |
$date_string = output_pref( $dt, 'metric', 'notime', 1 ); |
58 |
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => 'notime', dateonly => 1 }); |
51 |
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)'; |
59 |
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)'; |
52 |
|
60 |
|
53 |
$date_string = output_pref_due( $dt, 'metric', '24hr' ); |
61 |
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' }); |
54 |
cmp_ok $date_string, 'eq', '16/06/2011 12:00', |
62 |
cmp_ok $date_string, 'eq', '16/06/2011 12:00', |
55 |
'output_pref_due preserves non midnight HH:SS'; |
63 |
'output_pref_due preserves non midnight HH:SS'; |
56 |
|
64 |
|
57 |
$dt->set_hour(23); |
65 |
$dt->set_hour(23); |
58 |
$dt->set_minute(59); |
66 |
$dt->set_minute(59); |
59 |
$date_string = output_pref_due( $dt, 'metric', '24hr' ); |
67 |
$date_string = output_pref_due({ dt => $dt, dateformat => 'metric', timeformat => '24hr' }); |
60 |
cmp_ok $date_string, 'eq', '16/06/2011', |
68 |
cmp_ok $date_string, 'eq', '16/06/2011', |
61 |
'output_pref_due truncates HH:SS at midnight'; |
69 |
'output_pref_due truncates HH:SS at midnight'; |
62 |
|
70 |
|
63 |
- |
|
|