From ab6090ef2dea9f99c71465c6ad48d061e58b6997 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 28 Aug 2016 21:43:54 -0700 Subject: [PATCH] Util.pm: parse_any_date: allow 'UTC' for 'Z' Signed-off-by: Kyle J. McKay --- Girocco/Util.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Girocco/Util.pm b/Girocco/Util.pm index 98eb0dc..4502ed2 100644 --- a/Girocco/Util.pm +++ b/Girocco/Util.pm @@ -692,7 +692,7 @@ sub parse_rfc2822_date { # Will parse any supported date format. Actually there are three formats # currently supported: # 1. RFC 2822 (uses parse_rfc2822_date) -# 2. RFC 3339 / ISO 8601 (T may be ' ' or '_', 'Z' is optional, ':' optional in TZ) +# 2. RFC 3339 / ISO 8601 (T may be ' ' or '_', 'Z' is optional or may be 'UTC', ':' optional in TZ) # 3. Same as #2 except no colons or hyphens allowed and hours MUST be 2 digits # 4. unix seconds since epoch with optional +/- trailing TZ (may not have a ':') # Returns undef if unsupported date. @@ -712,15 +712,16 @@ sub parse_any_date { $$tzoff = $off if ref($tzoff) eq 'SCALAR'; return $ts; } - if ($dstr =~ /^\s*(\d{4})-(\d{2})-(\d{2})[Tt _](\d{1,2}):(\d{2}):(\d{2})(?:[ _]?([Zz]|(?:[-+]\d{1,2}:?\d{2})))?\s*$/ || - $dstr =~ /^\s*(\d{4})(\d{2})(\d{2})[Tt _](\d{2})(\d{2})(\d{2})(?:[ _]?([Zz]|(?:[-+]\d{2}\d{2})))?\s*$/) { + if ($dstr =~ /^\s*(\d{4})-(\d{2})-(\d{2})[Tt _](\d{1,2}):(\d{2}):(\d{2})(?:[ _]?([Zz]|[Uu][Tt][Cc]|(?:[-+]\d{1,2}:?\d{2})))?\s*$/ || + $dstr =~ /^\s*(\d{4})(\d{2})(\d{2})[Tt _](\d{2})(\d{2})(\d{2})(?:[ _]?([Zz]|[Uu][Tt][Cc]|(?:[-+]\d{2}\d{2})))?\s*$/) { my ($Y,$m,$d,$H,$M,$S,$z) = ($1,$2,$3,$4,$5,$6,$7||''); my $seconds = timegm(0+$S, 0+$M, 0+$H, 0+$d, $m-1, $Y-1900); defined($z) && $z ne '' or $z = 'Z'; + $z = uc($z); $z =~ s/://; substr($z,1,0) = '0' if length($z) == 4; my $off = 0; - if (uc($z) ne 'Z') { + if ($z ne 'Z' && $z ne 'UTC') { $off = 60 * (60 * (0+substr($z,1,2)) + (0+substr($z,3,2))); $off = -$off if substr($z,0,1) eq '-'; } -- 2.11.4.GIT