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

(-)a/Koha/DateUtils.pm (-3 / +3 lines)
Lines 142-148 sub dt_from_string { Link Here
142
        die "Invalid dateformat parameter ($date_format)";
142
        die "Invalid dateformat parameter ($date_format)";
143
    }
143
    }
144
144
145
    # Add the faculative time part [hh:mm[:ss]]
145
    # Add the facultative time part including time zone offset; ISO8601 allows +02 or +0200 too
146
    my $time_re .= qr{
146
    my $time_re .= qr{
147
            (
147
            (
148
                [Tt]?
148
                [Tt]?
Lines 159-165 sub dt_from_string { Link Here
159
                    (?<ampm>\w{2})
159
                    (?<ampm>\w{2})
160
                )?
160
                )?
161
                (
161
                (
162
                    (?<utc>[Zz]$)|((?<offset>[\+|\-])(?<hours>[01][0-9]|2[0-3]):(?<minutes>[0-5][0-9]))
162
                    (?<utc>[Zz]$)|((?<offset>[\+|\-])(?<hours>[01][0-9]|2[0-3]):?(?<minutes>[0-5][0-9])?)
163
                )?
163
                )?
164
            )?
164
            )?
165
    }xms;
165
    }xms;
Lines 183-189 sub dt_from_string { Link Here
183
        }
183
        }
184
        if ( $+{offset} ) {
184
        if ( $+{offset} ) {
185
            # If offset given, set inbound timezone using it.
185
            # If offset given, set inbound timezone using it.
186
            $tz = DateTime::TimeZone->new( name => $+{offset} . $+{hours} . $+{minutes} );
186
            $tz = DateTime::TimeZone->new( name => $+{offset} . $+{hours} . ( $+{minutes} || '00' ) );
187
        }
187
        }
188
    } elsif ( $do_fallback && $date_string =~ $fallback_re ) {
188
    } elsif ( $do_fallback && $date_string =~ $fallback_re ) {
189
        %dt_params = (
189
        %dt_params = (
(-)a/t/DateUtils.t (-3 / +8 lines)
Lines 144-150 like( $@, qr/.*does not match the date format \(rfc3339\).*/, 'dt_from_string sh Link Here
144
144
145
# ISO string tests
145
# ISO string tests
146
subtest 'dt_from_string - iso format' => sub {
146
subtest 'dt_from_string - iso format' => sub {
147
    plan tests => 5;
147
    plan tests => 7;
148
148
149
    my $module_context = Test::MockModule->new('C4::Context');
149
    my $module_context = Test::MockModule->new('C4::Context');
150
    $module_context->mock(
150
    $module_context->mock(
Lines 175-182 subtest 'dt_from_string - iso format' => sub { Link Here
175
    # Sunday January 01, 2012 23:59:59 (UTC)
175
    # Sunday January 01, 2012 23:59:59 (UTC)
176
176
177
    $dt_iso = dt_from_string( '2012-01-01T23:59:59+02:00', 'iso' );
177
    $dt_iso = dt_from_string( '2012-01-01T23:59:59+02:00', 'iso' );
178
    cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with offset' );
178
    cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with offset +02:00' );
179
    # Sunday January 01, 2012 21:59:59 (UTC) == Sunday January 01, 2012 23:59:59 Europe/Athens (EET/+02:00)
179
    # Sunday January 01, 2012 21:59:59 (UTC) == Sunday January 01, 2012 23:59:59 Europe/Athens (EET/+02:00)
180
    # Allow +02 or +0200 too
181
    $dt_iso = dt_from_string( '2012-01-01T23:59:59+02', 'iso' );
182
    cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with offset +02' );
183
    $dt_iso = dt_from_string( '2012-01-01T23:59:59+0200', 'iso' );
184
    cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with offset +0200' );
185
180
};
186
};
181
187
182
# Return undef if passed mysql 0 dates
188
# Return undef if passed mysql 0 dates
183
- 

Return to bug 29718