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

Properly adjust invalid dates in RecurrenceRule enumeration #1077

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

Conversation

hristost
Copy link
Contributor

@hristost hristost commented Dec 9, 2024

In recurrence rules without a strict matching policy, we'd sometimes come across dates which don't exist (such as February 29, 2009). When adjusting these dates, we were passing unadjusted date components. That resulted in adjusted dates with the highest unspecified component different than the original date. For example, adjusting February 29, 2009 to match components {month: 2, day: 29} would result February 29, 2012, instead of Match 1 or February 28 of the same year.

Adjusting the date components (that is, setting the year to 2009 for the example above) fixes this. This is what we already do in Calendar.dates(byMatching: ...)

In recurrence rules without a strict matching policy, we'd sometimes come across
dates which don't exist (such as February 29, 2009). When adjusting these dates,
we were passing unadjusted date components. That resulted in adjusted dates with
the highest unspecified component different than the original date. For example,
adjusting February 29, 2009 to match components {month: 2, day: 29} would result
February 29, 2012, instead of Match 1 or February 28 of the same year.

Adjusting the date components (that is, setting the year to 2009 for the example
above) fixes this. This is what we already do in Calendar.dates(byMatching: ...)
@hristost
Copy link
Contributor Author

hristost commented Dec 9, 2024

@swift-ci please test

let rangeStart = Date(timeIntervalSince1970: 946684800.0) // 2000-01-01T00:00:00-0000
let rangeEnd = Date(timeIntervalSince1970: 1262304000.0) // 2010-01-01T00:00:00-0000
var birthdays = rule.recurrences(of: rangeStart, in: rangeStart..<rangeEnd).makeIterator()
// ^ The initial date here does not matter, since the rule will change the month and day
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the initial date does matter in a sense -- it does affect hour, minute and second of the results. Perhaps rephrase this comment to clarify that the initial date does not affect specifically the month and day of the results?

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.

2 participants