Skip to content

fix Calendar.RecurrenceRule #1284

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lukaskollmer
Copy link

This PR attempts to fix #1283, by adjisting Calendar.DatesByRecurring.Iterator to maintain nanosecond precision on the dates it produces, if the original start date had a non-zero nanosecond component.

This brings the behaviour of the Calendar.RecurrenceRule API in line with how it was defined and described in the proposal.

@@ -232,6 +235,8 @@ extension Calendar {
}
var componentsForEnumerating = recurrence.calendar._dateComponents(components, from: start)

startDateNanoseconds = start.timeIntervalSince1970.remainder(dividingBy: 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work if we modify components above to include nanoseconds so the information is readily available in componentsForEnumerating, so that we don't have to do this manual adjustment here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itingliu that was my first attempt, but it doesn't work.

in my understanding, the issue is that Calendar.DatesByRecurring's underlying baseRecurrence (Calendar.DatesByMatching) will always return only whole-second-rounded dates (though this isn't documented, afaict), so we'd need to adjust that type's behaviour instead (which i decided against bc i wasn't sure whether this would affect any other dependent code, and i figured instead going with the simplest possible fix would be the best approach)

@itingliu
Copy link
Contributor

@swift-ci please test

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.

RecurrenceRule produces incorrect sequences for start dates with non-zero nanosecond components
2 participants