Skip to content

Commit 4c16c87

Browse files
committed
Bug 1068014: skip strptime() in datetime_from() if the date is in a standard format
1 parent c8c2d8e commit 4c16c87

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Bugzilla/Util.pm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,14 @@ sub datetime_from {
548548
# In the database, this is the "0" date.
549549
return undef if $date =~ /^0000/;
550550

551-
# strptime($date) returns an empty array if $date has an invalid
552-
# date format.
553-
my @time = strptime($date);
551+
my @time;
552+
# Most dates will be in this format, avoid strptime's generic parser
553+
if ($date =~ /^(\d{4})[\.-](\d{2})[\.-](\d{2})(?: (\d{2}):(\d{2}):(\d{2}))?$/) {
554+
@time = ($6, $5, $4, $3, $2 - 1, $1 - 1900, undef);
555+
}
556+
else {
557+
@time = strptime($date);
558+
}
554559

555560
unless (scalar @time) {
556561
# If an unknown timezone is passed (such as MSK, for Moskow),

0 commit comments

Comments
 (0)