Bug 5549 : Merge old and new DateUtils tests
[koha_gimpoz] / t / DateUtils.t
1 use strict;
2 use warnings;
3 use 5.010;
4 use DateTime;
5 use DateTime::TimeZone;
6
7 use C4::Context;
8 use Test::More tests => 9;    # last test to print
9
10 BEGIN { use_ok('Koha::DateUtils'); }
11
12 my $tz = C4::Context->tz;
13
14 isa_ok( $tz, 'DateTime::TimeZone', 'Context returns timezone object' );
15
16 my $testdate_iso = '2011-06-16';                   # Bloomsday 2011
17 my $dt = dt_from_string( $testdate_iso, 'iso' );
18
19 isa_ok( $dt, 'DateTime', 'dt_from_string returns a DateTime object' );
20
21 cmp_ok( $dt->ymd(), 'eq', $testdate_iso, 'Returned object matches input' );
22
23 $dt->set_hour(12);
24 $dt->set_minute(0);
25
26 my $date_string = output_pref( $dt, 'iso' );
27 cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output';
28
29 $date_string = output_pref( $dt, 'us' );
30 cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output';
31
32 # metric should return the French Revolutionary Calendar Really
33 $date_string = output_pref( $dt, 'metric' );
34 cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output';
35
36 my $dear_dirty_dublin = DateTime::TimeZone->new( name => 'Europe/Dublin');
37 my $new_dt = dt_from_string('16/06/2011', 'metric',  $dear_dirty_dublin);
38
39 isa_ok( $new_dt, 'DateTime', 'Create DateTime with different timezone' );
40
41 cmp_ok( $new_dt->ymd(), 'eq', $testdate_iso, 'Returned Dublin object matches input' );
42