Added support for nextDate and enumerateDates to Calendar#93
Added support for nextDate and enumerateDates to Calendar#93fhasse95 wants to merge 27 commits intoskiptools:mainfrom
Conversation
| var previouslyReturnedMatchDate: Date? = nil | ||
| var iterations = -1 | ||
|
|
||
| repeat { |
There was a problem hiding this comment.
This STOP_EXHAUSTIVE_SEARCH_AFTER_MAX_ITERATIONS approach seems rather heavy-handed to me. I assume there's no equivalent function in Java's Calendar logic?
How does Foundation's Calendar do it?
There was a problem hiding this comment.
As far as I know, Java's Calendar does not have a direct native equivalent to Apple's enumerateDates function which is why I decided to base the implementation on the logic found in the Swift Foundation library.
I agree that this approach seems heavy-handed for preventing infinite loops. However, the Swift Foundation implements it in exactly the same way (see: https://github.com/swiftlang/swift-foundation/blob/main/Sources/FoundationEssentials/Calendar/Calendar_Enumerate.swift#L472C9-L472C62).
This PR extends the
Calendarclass to include support fornextDateandenumerateDates.The core logic was primarily adapted from the Swift Foundation repository repository to ensure parity with the native Swift behavior and minimize the risk of logic errors inherent in a full reimplementation. Since Skip currently only supports the Gregorian calendar, non-essential special cases were removed (e.g., lunar calendar offsets).
To ensure stability, I added several unit tests covering ranges, intervals, and enumeration. However, due to the complexity of calendar edge cases, it's possible that I overlooked a scenario.
Therefore, if you notice anaything, please let me know! 😊
Thank you for contributing to the Skip project! Please use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.
Please review the contribution guide at https://skip.dev/docs/contributing/ for advice and guidance on making high-quality PRs.
Skip Pull Request Checklist:
swift testI used AI for assistance in creating additional unit tests for the calendar components and for consulting on Java-specific Calendar behaviors. Verification was done by manually reviewing all test cases, adjusting range expectations to match platform-specific constants, and ensuring the tests pass on both environments.