View | Details | Raw Unified | Return to bug 13601
Collapse All | Expand All

(-)a/t/DateUtils.t (-9 / +37 lines)
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 => 44;
6
use Test::More tests => 54;
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 26-37 $dt->set_minute(0); Link Here
26
my $date_string;
27
my $date_string;
27
28
28
my $module_context = new Test::MockModule('C4::Context');
29
my $module_context = new Test::MockModule('C4::Context');
29
$module_context->mock(
30
30
    'preference',
31
t::lib::Mocks::mock_preference('dateformat', 'us');
31
    sub {
32
        return 'us';
33
    }
34
);
35
32
36
my $dateformat = C4::Context->preference('dateformat');
33
my $dateformat = C4::Context->preference('dateformat');
37
cmp_ok  output_pref({ dt => $dt, dateformat => $dateformat }),
34
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" );
114
is( $dt0, undef, "undefined returned for 0 iso date" );
118
115
119
# Return undef if passed mysql 9999-* date
116
# Return undef if passed mysql 9999-* date
120
my $dt9999 = dt_from_string( '9999-12-31' );
117
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" );
118
is( $dt9999->ymd(), '9999-12-31', "dt_from_string should return a DateTime object for 9999-12-31" );
122
119
123
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric', '24hr' );
120
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric', '24hr' );
Lines 182-184 $module_context->mock( Link Here
182
179
183
$dt = dt_from_string('2014-03-30 02:00:00');
180
$dt = dt_from_string('2014-03-30 02:00:00');
184
isa_ok( $dt, 'DateTime', 'dt_from_string should return a DateTime object if a DST is given' );
181
isa_ok( $dt, 'DateTime', 'dt_from_string should return a DateTime object if a DST is given' );
185
- 
182
183
# Test dt_from_string
184
t::lib::Mocks::mock_preference('dateformat', 'metric');
185
t::lib::Mocks::mock_preference('TimeFormat', '24hr');
186
187
# dt_from_string should take into account the dateformat pref, or the given parameter
188
$dt = dt_from_string('31/01/2015');
189
is( ref($dt), 'DateTime', '31/01/2015 is a correct date in metric format' );
190
is( output_pref( { dt => $dt, dateonly => 1 } ), '31/01/2015' );
191
$dt = eval { dt_from_string( '31/01/2015', 'iso' ); };
192
is( ref($dt), '', '31/01/2015 is not a correct date in iso format' );
193
$dt = eval { dt_from_string( '01/01/2015', 'iso' ); };
194
is( ref($dt), '', '01/01/2015 is not a correct date in iso format' );
195
$dt = eval { dt_from_string( '31/01/2015', 'us' ); };
196
is( ref($dt), '', '31/01/2015 is not a correct date in us format' );
197
$dt = dt_from_string( '01/01/2015', 'us' );
198
is( ref($dt), 'DateTime', '01/01/2015 is a correct date in us format' );
199
200
201
# default value for hh and mm is 00:00
202
$dt = dt_from_string('31/01/2015');
203
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' );
204
205
$dt = dt_from_string('31/01/2015 12:34');
206
is( output_pref( { dt => $dt } ), '31/01/2015 12:34', 'dt_from_string should match hh:mm' );
207
208
$dt = dt_from_string('31/01/2015 12:34:56');
209
is( output_pref( { dt => $dt } ), '31/01/2015 12:34', 'dt_from_string should match hh:mm:ss' );
210
211
# date before 1900
212
$dt = dt_from_string('01/01/1900');
213
is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string should manage date < 1900' );

Return to bug 13601