6 use Koha::DateUtils qw( dt_from_string output_pref );
9 use Test::More tests => 9;
13 use_ok('Koha::Template::Plugin::KohaDates');
16 my $module_context = Test::MockModule->new('C4::Context');
18 my $date = "1973-05-21";
19 my $context = C4::Context->new();
21 my $filter = Koha::Template::Plugin::KohaDates->new();
22 ok ($filter, "new()");
24 t::lib::Mocks::mock_preference( "dateformat", 'iso' );
25 $context->clear_syspref_cache();
27 my $filtered_date = $filter->filter($date);
28 is ($filtered_date,$date, "iso conversion") or diag ("iso conversion fails");
30 #$filter = Koha::Template::Plugin::KohaDates->new();
31 t::lib::Mocks::mock_preference( "dateformat", 'us' );
32 $context->clear_syspref_cache();
34 $filtered_date = $filter->filter($date);
35 is ($filtered_date,'05/21/1973', "us conversion") or diag ("us conversion fails $filtered_date");
37 t::lib::Mocks::mock_preference( "dateformat", 'metric' );
38 $context->clear_syspref_cache();
40 $filtered_date = $filter->filter($date);
41 is ($filtered_date,'21/05/1973', "metric conversion") or diag ("metric conversion fails $filtered_date");
43 $module_context->mock(
46 return DateTime::TimeZone->new( name => 'Europe/Lisbon' );
50 $filtered_date = $filter->filter('1979-04-01');
51 is( $filtered_date, '01/04/1979', 'us: dt_from_string should return the valid date if a dst is given' );
53 $filtered_date = $filter->filter('1979-04-01', undef, { dateformat => 'iso' } );
54 is( $filtered_date, '1979-04-01', 'date should be returned in ISO if dateformat is passed with a value of iso' );
56 is( Koha::DateUtils::output_pref( dt_from_string ), $filter->output_preference( dt_from_string ), 'Filter output_preference method output matches output_pref' );
58 $module_context->mock(
61 return DateTime::TimeZone->new( name => 'Europe/Paris' );
65 $filtered_date = $filter->filter('2014-03-30 02:00:00');
66 is( $filtered_date, '30/03/2014', 'us: dt_from_string should return a DateTime object if a DST is given' );