--- include/classes/parsers/CRelativeTimeParser.php.bak 2022-03-29 00:13:41.903955086 +0900 +++ include/classes/parsers/CRelativeTimeParser.php 2022-04-01 00:06:45.815977824 +0900 @@ -199,7 +199,25 @@ 'y' => 'year' ]; - $date->modify($token['sign'].$token['value'].' '.$units[$token['suffix']]); + if ($token['suffix'] === 'M') { + /* correctly calculates end of months + * see the example in https://www.php.net/manual/en/datetime.modify.php */ + $date0 = clone($date); + $date1 = clone($date); + $date2 = clone($date); + $date->modify($token['sign'].$token['value'].' '.$units[$token['suffix']]); + $date1->modify($token['sign'].$token['value'].' '.$units[$token['suffix']]); + $date1->modify(-1 * intval($token['sign'].$token['value']).' '.$units[$token['suffix']]); + if ($date1 != $date2) { + $date->modify('last day of last month'); + } + elseif ($date0 == $date2->modify('last day of this month')) { + $date->modify('last day of this month'); + } + } + else { + $date->modify($token['sign'].$token['value'].' '.$units[$token['suffix']]); + } break; } }