From a9b9e3661656d8ee1d65846e646d821fdd36fc12 Mon Sep 17 00:00:00 2001 From: Ling Ho Date: Wed, 31 May 2023 15:07:41 -0700 Subject: [PATCH] Fixed SqlifyDate function to not return invalid dates when "m" is used. https://bugs.webkit.org/show_bug.cgi?id=257546 Reviewed by Alexey Proskuryakov. Modified the SqlifyDate function such that when "m" is entered, it converts to month multiplied by 31 days, similar to how it treats "d" where it multiplies the number by 7. * Websites/bugs.webkit.org/Bugzilla/Search.pm: (SqlifyDate): Canonical link: https://commits.webkit.org/264758@main --- Websites/bugs.webkit.org/Bugzilla/Search.pm | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Websites/bugs.webkit.org/Bugzilla/Search.pm b/Websites/bugs.webkit.org/Bugzilla/Search.pm index 646f949f5481..beffd2e2e1c6 100644 --- a/Websites/bugs.webkit.org/Bugzilla/Search.pm +++ b/Websites/bugs.webkit.org/Bugzilla/Search.pm @@ -2217,7 +2217,20 @@ sub SqlifyDate { my ($sec, $min, $hour, $mday, $month, $year, $wday) = localtime($date); if ($sign && $sign eq '+') { $amount = -$amount; } $startof = 1 if $amount == 0; - if ($unit eq 'w') { # convert weeks to days +# WEBKIT_CHANGES: Fixed invalid date returns on some occasions. + if ($unit eq 'm') { + $month -= $amount; + $year += floor($month/12); + $month %= 12; + if ($startof) { + return sprintf("%4d-%02d-01 00:00:00", $year+1900, $month+1); + } + else { + $amount = 31*$amount; + $unit = 'd'; + } + } + elseif ($unit eq 'w') { # convert weeks to days $amount = 7*$amount; $amount += $wday if $startof; $unit = 'd'; @@ -2239,18 +2252,6 @@ sub SqlifyDate { $year+1900-$amount, $month+1, $mday, $hour, $min, $sec); } } - elsif ($unit eq 'm') { - $month -= $amount; - $year += floor($month/12); - $month %= 12; - if ($startof) { - return sprintf("%4d-%02d-01 00:00:00", $year+1900, $month+1); - } - else { - return sprintf("%4d-%02d-%02d %02d:%02d:%02d", - $year+1900, $month+1, $mday, $hour, $min, $sec); - } - } elsif ($unit eq 'h') { # Special case for 'beginning of an hour' if ($startof) {