]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1068014: skip strptime() in datetime_from() if the date is in a standard format
authorByron Jones <glob@mozilla.com>
Thu, 18 Sep 2014 05:10:01 +0000 (13:10 +0800)
committerByron Jones <glob@mozilla.com>
Thu, 18 Sep 2014 05:10:01 +0000 (13:10 +0800)
r=dylan,a=glob

Bugzilla/Util.pm

index be65b46c65515a57a33a791ae30644824ac7fcf2..670f5f8f28b1d2350e2a8432fc0c3e4944b8b7d1 100644 (file)
@@ -552,9 +552,14 @@ sub datetime_from {
     # In the database, this is the "0" date.
     return undef if $date =~ /^0000/;
 
-    # strptime($date) returns an empty array if $date has an invalid
-    # date format.
-    my @time = strptime($date);
+    my @time;
+    # Most dates will be in this format, avoid strptime's generic parser
+    if ($date =~ /^(\d{4})[\.-](\d{2})[\.-](\d{2})(?: (\d{2}):(\d{2}):(\d{2}))?$/) {
+        @time = ($6, $5, $4, $3, $2 - 1, $1 - 1900, undef);
+    }
+    else {
+        @time = strptime($date);
+    }
 
     unless (scalar @time) {
         # If an unknown timezone is passed (such as MSK, for Moskow),