Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for DateTimeException: Invalid date 'FEBRUARY 31' #552

Merged
merged 2 commits into from
Mar 20, 2024
Merged

Fix for DateTimeException: Invalid date 'FEBRUARY 31' #552

merged 2 commits into from
Mar 20, 2024

Conversation

Sheryv
Copy link
Contributor

@Sheryv Sheryv commented Mar 20, 2024

This PR fixes 2 issues in calev-core:

  1. Prevents throwing DateTimeException: Invalid date 'FEBRUARY 31' :

    The following example

        val expression = CalEvent(AllWeekdays, date(All, 2.c, All), time(0 #/ 6, 0.c, 0.c))
    
        val next = expression
          .nextElapse(OffsetDateTime.parse("2024-01-31T18:00+01:00").toZonedDateTime)
          .get
    
        assertEquals(next, ZonedDateTime.parse("2024-02-01T00:00+01:00"))

    in the current library version, will throw

    java.time.DateTimeException: Invalid date 'FEBRUARY 31'
    
        at java.base/java.time.LocalDate.create(LocalDate.java:459)
        at java.base/java.time.LocalDate.of(LocalDate.java:275)
        at com.github.eikek.calev.internal.DefaultTrigger$Date.toLocalDate(DefaultTrigger.scala:96)
        at com.github.eikek.calev.internal.DefaultTrigger$Calc.maxValue(DefaultTrigger.scala:197)
        at com.github.eikek.calev.internal.DefaultTrigger$Calc.atStartBelow(DefaultTrigger.scala:221)
        at com.github.eikek.calev.internal.DefaultTrigger$Calc.atStartBelowCurrent(DefaultTrigger.scala:227)
        at com.github.eikek.calev.internal.DefaultTrigger$.run(DefaultTrigger.scala:83)
        at com.github.eikek.calev.internal.DefaultTrigger$.go$1(DefaultTrigger.scala:40)
        at com.github.eikek.calev.internal.DefaultTrigger$.next(DefaultTrigger.scala:51)
        at com.github.eikek.calev.CalEvent.nextElapse(CalEvent.scala:44)
        at com.github.eikek.calev.CalEventTest.$anonfun$new$45(CalEventTest.scala:103)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    

    Adding range check for the day field fixes that particular problem

  2. Prevents application freeze when negative count is passed to Trigger.nextRepeat() by adding validation

@eikek
Copy link
Owner

eikek commented Mar 20, 2024

Thank you very much!

@eikek eikek merged commit c7983f1 into eikek:master Mar 20, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants