6 use Test::More tests => 91;
8 use_ok('C4::Dates', qw(format_date format_date_in_iso));
12 iso => ['2001-01-01','1989-09-21'],
13 metric => ["01-01-2001",'21-09-1989'],
14 us => ["01-01-2001",'09-21-1989'],
15 sql => ['20010101 010101',
19 my ($date, $format, $today, $today0, $val, $re, $syspref);
20 my @formats = sort keys %thash;
21 diag "\n Testing Legacy Functions: format_date and format_date_in_iso";
22 ok($syspref = C4::Dates->new->format(), "Your system preference is: $syspref");
24 foreach (@{$thash{'iso'}}) {
25 ok($val = format_date($_), "format_date('$_'): $val" );
27 foreach (@{$thash{$syspref}}) {
28 ok($val = format_date_in_iso($_), "format_date_in_iso('$_'): $val" );
30 ok($today0 = C4::Dates->today(), "(default) CLASS ->today : $today0" );
31 diag "\nTesting " . scalar(@formats) . " formats.\nTesting no input (defaults):\n";
34 my $pre = sprintf '(%-6s)', $_;
35 ok($date = C4::Dates->new(), "$pre Date Creation : new()");
36 ok($_ eq ($format = $date->format($_)), "$pre format($_) : $format" );
37 ok($format = $date->visual(), "$pre visual() : $format" );
38 ok($today = $date->output(), "$pre output() : $today" );
39 ok($today = $date->today(), "$pre object->today : $today" );
43 diag "\nTesting with inputs:\n";
44 foreach $format (@formats) {
45 my $pre = sprintf '(%-6s)', $format;
46 foreach my $testval (@{$thash{ $format }}) {
47 ok($date = C4::Dates->new($testval,$format), "$pre Date Creation : new('$testval','$format')");
48 ok($re = $date->regexp, "$pre has regexp()" );
49 ok($val = $date->output(), "$pre output() : $val" );
50 foreach (grep {!/$format/} @formats) {
51 ok($today = $date->output($_), "$pre output(" . sprintf("%8s","'$_'") . "): $today");
53 ok($today = $date->today(), "$pre object->today : $today" );
54 # ok($today == ($today = C4::Dates->today()), "$pre CLASS ->today : $today" );
55 ok($val = $date->output(), "$pre output() : $val" );
56 # ok($format eq ($format = $date->format()), "$pre format() : $format" );