Support HALF_DAY periodicity for AM/PM date patterns - #1051
Open
seonwooj0810 wants to merge 1 commit into
Open
Conversation
The HALF_DAY periodicity type and its printPeriodicity() message have
existed since LBCORE-11 (2008), but HALF_DAY was never added to
PeriodicityType.VALID_ORDERED_LIST and no HALF_DAY branch was wired into
RollingCalendar. As a result a TimeBasedRollingPolicy whose date pattern
carries the AM/PM token (e.g. %d{yyyy-MM-dd-a}) is detected as TOP_OF_DAY
and rolls over only at midnight instead of at 00:00 and 12:00.
Add HALF_DAY to the ordered detection list and implement the missing
HALF_DAY cases in innerGetEndOfNextNthPeriod (floor to the current
half-day boundary, advance in 12h steps), periodBarriersCrossed, and
isCollisionFree. Add regression tests to RollingCalendarTest.
Fixes qos-ch#976
Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.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.
Fixes #976
Root cause
The
HALF_DAYperiodicity type and itsRollingCalendar.printPeriodicity()message ("Roll-over at midday and midnight.") have existed since LBCORE-11 (2008), butHALF_DAYwas never added toPeriodicityType.VALID_ORDERED_LIST, andRollingCalendarhas noHALF_DAYbranch in its switch statements. SocomputePeriodicityType()can never select it: aTimeBasedRollingPolicywhose date pattern carries the AM/PM token but no finer time token (e.g.%d{yyyy-MM-dd-a}) falls through toTOP_OF_DAYand rolls over only at midnight, logging "Roll-over at midnight." instead of rotating at both 00:00 and 12:00.Change
PeriodicityType: insertHALF_DAYintoVALID_ORDERED_LISTbetweenTOP_OF_HOURandTOP_OF_DAY. Because detection returns the shortest matching period, this only affects patterns that distinguish 00:00 from 12:00 but nothing finer (i.e. theatoken) — patterns that already match atTOP_OF_HOURor below are unchanged.RollingCalendar.innerGetEndOfNextNthPeriod: add theHALF_DAYcase — floor to the current half-day boundary (00:00 or 12:00) and advance in 12h steps, mirroring the existingTOP_OF_DAYflooring.RollingCalendar.periodBarriersCrossed: addHALF_DAY(previously it hit thedefaultbranch and threwIllegalStateException).RollingCalendar.isCollisionFree: addHALF_DAY— an isolatedawithout a date component repeats every 24h, so a 1-day collision check flags it.Test evidence
Added regression coverage to
RollingCalendarTest(all pass; each fails on currentmasterbefore the fix):testPeriodicity:yyyy-MM-dd-aandyyyy-MM-dd anow resolve toHALF_DAY(previouslyTOP_OF_DAY).testVaryingNumberOfHalfDailyPeriods:getEndOfNextNthPeriodadvances in exact 12h boundaries across a range of periods.testBarrierCrossingComputation: 3 half-day barriers over 36h.testCollisionFreenes:yyyy-MM-dd-ais collision-free; isolatedais not.Verification done:
mvn -pl logback-core -am test -Dtest=RollingCalendarTest→ 10/10 pass. Ran the fullch.qos.logback.core.rolling.*suite: all rolling tests pass; the only errors are 3 pre-existingInaccessibleObjectExceptions inRollingFileAppenderTest(JPMS reflection intoch.qos.logback.core.appender), which are unrelated to this change and reproduce identically on a cleanmastercheckout when the test JVM is JDK 25.