BUG FIX: Fix month rounding logic when a fixed day is set#52
Open
flintfromthebasement wants to merge 1 commit intostrangerstudios:devfrom
Open
Conversation
…_fixDate() When using a date code like Y2-M1-01, the "next occurrence" month-rounding logic would fire even when a fixed day of month (-01) was explicitly set. Since day 01 is almost always < current day, the condition would add an extra month. For December, this causes month 13 → January next year, burning one of the years and producing wrong output. Root cause: The guard at line 104 only checked if this was the first loop iteration (0 == $i), but didn't check whether a fixed day was explicitly set ($set_d). The rounding is only meaningful when no specific day is given (e.g. M1 without a day component). Fix: Add && 0 == $set_d to the condition so the rounding only applies when no explicit day was provided. Fixes: strangerstudios#32 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the month-rounding bug in
pmprosed_fixDate()where date codes with explicit days (e.g.,Y2-M1-01) would incorrectly add an extra month.The Bug
When using a date code like
Y2-M1-01, the "next occurrence" month-rounding logic at line 104 fires even when a fixed day of month (-01) is explicitly set. Since day01is almost always less than the current day, the condition$temp_d < $current_dis nearly always true, adding an extra month.For December, this causes month 13 → January next year, which burns one of the
$add_yearscount and produces completely wrong output (Jan next year instead of Dec next year).Root Cause
The guard at line 104 only checked
0 == $i(first loop iteration), but didn't check whether a fixed day was explicitly set ($set_d). The rounding is only meaningful when no specific day is given — e.g.,M1without a day component.The Fix
Add
&& 0 == $set_dto the condition so the rounding only applies when no explicit day was provided.Changed:
How to Test
Y2-M1-01Y1-M0-12in December — confirm you get December next year, not JanuaryFixes: #32