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

(-)a/t/DateUtils.t (-5 / +12 lines)
Lines 4-10 use DateTime::TimeZone; Link Here
4
4
5
use C4::Context;
5
use C4::Context;
6
6
7
use Test::More tests => 79;
7
use Test::More tests => 80;
8
8
9
use Test::MockModule;
9
use Test::MockModule;
10
use Test::Warn;
10
use Test::Warn;
Lines 146-154 like( $@, qr/.*does not match the date format \(rfc3339\).*/, 'dt_from_string sh Link Here
146
subtest 'dt_from_string - iso format' => sub {
146
subtest 'dt_from_string - iso format' => sub {
147
    plan tests => 6;
147
    plan tests => 6;
148
148
149
    my $module_context = Test::MockModule->new('C4::Context');
150
    $module_context->mock(
151
        'tz',
152
        sub {
153
            return DateTime::TimeZone->new( name => 'Europe/Paris' );
154
        }
155
    );
156
149
    # Dateonly
157
    # Dateonly
150
    my $dt_iso = dt_from_string( '2012-01-01', 'iso' );
158
    my $dt_iso = dt_from_string( '2012-01-01', 'iso' );
151
    cmp_ok( $dt_iso->epoch(), 'eq', '1325376000', 'dt_from_string handles dateonly string' );
159
    cmp_ok( $dt_iso->epoch(), 'eq', '1325372400', 'dt_from_string handles dateonly string' );
152
160
153
    eval {
161
    eval {
154
        $dt_iso = dt_from_string( '2012-01-32', 'iso' );
162
        $dt_iso = dt_from_string( '2012-01-32', 'iso' );
Lines 157-167 subtest 'dt_from_string - iso format' => sub { Link Here
157
165
158
    # Datetime
166
    # Datetime
159
    $dt_iso = dt_from_string( '2012-01-01T23:59:59', 'iso' );
167
    $dt_iso = dt_from_string( '2012-01-01T23:59:59', 'iso' );
160
    cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with no offset assumes "local"' );
168
    cmp_ok( $dt_iso->epoch(), 'eq', '1325458799', 'dt_from_string with no offset assumes "local"' );
161
169
162
    # Datetime with timezone
170
    # Datetime with timezone
163
    $dt_iso = dt_from_string( '2012-01-01T23:59:59Z', 'iso' );
171
    $dt_iso = dt_from_string( '2012-01-01T23:59:59Z', 'iso' );
164
    cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with UTC prescribed as Z' );
172
    cmp_ok( $dt_iso->epoch(), 'eq', '1325462399', 'dt_from_string with UTC prescribed as Z' );
165
173
166
    $dt_iso = dt_from_string( '2012-01-01T23:59:59+02:00', 'iso' );
174
    $dt_iso = dt_from_string( '2012-01-01T23:59:59+02:00', 'iso' );
167
    cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with offset' );
175
    cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with offset' );
168
- 

Return to bug 29718