Skip to content

Commit

Permalink
Fixed SqlifyDate function to not return invalid dates when "m" is used.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=257546
<rdar://problem/110075621>

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
  • Loading branch information
lingcherd committed May 31, 2023
1 parent 3ac3511 commit a9b9e36
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Websites/bugs.webkit.org/Bugzilla/Search.pm
Expand Up @@ -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';
Expand All @@ -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) {
Expand Down

0 comments on commit a9b9e36

Please sign in to comment.