Lines 3-11
use DateTime;
Link Here
|
3 |
use DateTime::TimeZone; |
3 |
use DateTime::TimeZone; |
4 |
|
4 |
|
5 |
use C4::Context; |
5 |
use C4::Context; |
6 |
use Test::More tests => 42; |
6 |
use Test::More tests => 52; |
7 |
use Test::MockModule; |
7 |
use Test::MockModule; |
8 |
use Time::HiRes qw/ gettimeofday /; |
8 |
use Time::HiRes qw/ gettimeofday /; |
|
|
9 |
use t::lib::Mocks; |
9 |
|
10 |
|
10 |
BEGIN { use_ok('Koha::DateUtils'); } |
11 |
BEGIN { use_ok('Koha::DateUtils'); } |
11 |
|
12 |
|
Lines 25-37
$dt->set_minute(0);
Link Here
|
25 |
|
26 |
|
26 |
my $date_string; |
27 |
my $date_string; |
27 |
|
28 |
|
28 |
my $module_context = new Test::MockModule('C4::Context'); |
29 |
t::lib::Mocks::mock_preference('dateformat', 'us'); |
29 |
$module_context->mock( |
|
|
30 |
'preference', |
31 |
sub { |
32 |
return 'us'; |
33 |
} |
34 |
); |
35 |
|
30 |
|
36 |
my $dateformat = C4::Context->preference('dateformat'); |
31 |
my $dateformat = C4::Context->preference('dateformat'); |
37 |
cmp_ok output_pref({ dt => $dt, dateformat => $dateformat }), |
32 |
cmp_ok output_pref({ dt => $dt, dateformat => $dateformat }), |
Lines 117-123
$dt0 = dt_from_string( '0000-00-00', 'iso' );
Link Here
|
117 |
is( $dt0, undef, "undefined returned for 0 iso date" ); |
112 |
is( $dt0, undef, "undefined returned for 0 iso date" ); |
118 |
|
113 |
|
119 |
# Return undef if passed mysql 9999-* date |
114 |
# Return undef if passed mysql 9999-* date |
120 |
my $dt9999 = dt_from_string( '9999-12-31' ); |
115 |
my $dt9999 = dt_from_string( '9999-12-31', 'sql' ); |
121 |
is( $dt9999->ymd(), '9999-12-31', "dt_from_string should return a DateTime object for 9999-12-31" ); |
116 |
is( $dt9999->ymd(), '9999-12-31', "dt_from_string should return a DateTime object for 9999-12-31" ); |
122 |
|
117 |
|
123 |
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric', '24hr' ); |
118 |
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric', '24hr' ); |
Lines 162-164
cmp_ok $date_string, 'eq', '12/11/2013 06:35 PM', 'as_due_date with hours and ti
Link Here
|
162 |
|
157 |
|
163 |
my $now = DateTime->now; |
158 |
my $now = DateTime->now; |
164 |
is( dt_from_string, $now, "Without parameter, dt_from_string should return today" ); |
159 |
is( dt_from_string, $now, "Without parameter, dt_from_string should return today" ); |
165 |
- |
160 |
|
|
|
161 |
# Test dt_from_string |
162 |
t::lib::Mocks::mock_preference('dateformat', 'metric'); |
163 |
t::lib::Mocks::mock_preference('TimeFormat', '24hr'); |
164 |
|
165 |
# dt_from_string should take into account the dateformat pref, or the given parameter |
166 |
$dt = dt_from_string('31/01/2015'); |
167 |
is( ref($dt), 'DateTime', '31/01/2015 is a correct date in metric format' ); |
168 |
is( output_pref( { dt => $dt, dateonly => 1 } ), '31/01/2015' ); |
169 |
$dt = eval { dt_from_string( '31/01/2015', 'iso' ); }; |
170 |
is( ref($dt), '', '31/01/2015 is not a correct date in iso format' ); |
171 |
$dt = eval { dt_from_string( '01/01/2015', 'iso' ); }; |
172 |
is( ref($dt), '', '01/01/2015 is not a correct date in iso format' ); |
173 |
$dt = eval { dt_from_string( '31/01/2015', 'us' ); }; |
174 |
is( ref($dt), '', '31/01/2015 is not a correct date in us format' ); |
175 |
$dt = dt_from_string( '01/01/2015', 'us' ); |
176 |
is( ref($dt), 'DateTime', '01/01/2015 is a correct date in us format' ); |
177 |
|
178 |
|
179 |
# default value for hh and mm is 00:00 |
180 |
$dt = dt_from_string('31/01/2015'); |
181 |
is( output_pref( { dt => $dt } ), '31/01/2015 00:00', 'dt_from_string should generate a DT object with 00:00 as default hh:mm' ); |
182 |
|
183 |
$dt = dt_from_string('31/01/2015 12:34'); |
184 |
is( output_pref( { dt => $dt } ), '31/01/2015 12:34', 'dt_from_string should match hh:mm' ); |
185 |
|
186 |
$dt = dt_from_string('31/01/2015 12:34:56'); |
187 |
is( output_pref( { dt => $dt } ), '31/01/2015 12:34', 'dt_from_string should match hh:mm:ss' ); |
188 |
|
189 |
# date before 1900 |
190 |
$dt = dt_from_string('01/01/1900'); |
191 |
is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string should manage date < 1900' ); |