Bug 29718: (QA follow-up) Add optional offset handling
ISO8601 optionally supports timezone offsets. If a timezone is ommited, we should assume 'local' time (Which in our case is instance configuration time), if we are passed 'Z' or 'z' we should set timezone to 'UTC', otherwise we should set the timezone to the passed offset. Whilst ISO8601 does NOT support AM/PM, I left that intact as it has historical relevance in Koha and we share the ISO parsing with SQL type parsing amongth other things. Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
9daea562a8
commit
da34328fc1
|
|
@ -143,7 +143,7 @@ sub dt_from_string {
|
|||
}
|
||||
|
||||
# Add the faculative time part [hh:mm[:ss]]
|
||||
my $time_re .= qr|
|
||||
my $time_re .= qr{
|
||||
(
|
||||
[Tt]?
|
||||
\s*
|
||||
|
|
@ -158,8 +158,11 @@ sub dt_from_string {
|
|||
\s
|
||||
(?<ampm>\w{2})
|
||||
)?
|
||||
(
|
||||
(?<utc>[Zz]$)|((?<offset>[\+|\-])(?<hours>[01][0-9]|2[0-3]):(?<minutes>[0-5][0-9]))
|
||||
)?
|
||||
)?
|
||||
|xms;
|
||||
}xms;
|
||||
$regex .= $time_re unless ( $date_format eq 'rfc3339' );
|
||||
$fallback_re .= $time_re;
|
||||
|
||||
|
|
@ -175,6 +178,9 @@ sub dt_from_string {
|
|||
second => $+{second},
|
||||
);
|
||||
$ampm = $+{ampm};
|
||||
if ( $+{utc} ) {
|
||||
$tz = DateTime::TimeZone->new( name => 'UTC' );
|
||||
}
|
||||
if ( $+{offset} ) {
|
||||
# If offset given, set inbound timezone using it.
|
||||
$tz = DateTime::TimeZone->new( name => $+{offset} . $+{hours} . $+{minutes} );
|
||||
|
|
|
|||
Loading…
Reference in New Issue