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

Calendar.dates(byMatching: ...) does not respect repeatedTimePolicy when .nanosecond is set #483

Open
hristost opened this issue Mar 14, 2024 · 1 comment

Comments

@hristost
Copy link
Contributor

When searching by dates matching date components, the repeatedTimePolicy field is not respected if the nanoseconds field is set. For example, we want to find the date expected which is just after a daylight switch:

let start    = Date(timeIntervalSince1970: 1730535600.0) // 2024-11-02T01:20:00-0700
let expected = Date(timeIntervalSince1970: 1730625600.0) // 2024-11-03T01:20:00-0800
        
var dc = DateComponents()
dc.hour = 1
dc.minute = 20
dc.second = 0
dc.nanosecond = 0
        
var sequenceIterator = gregorian.dates(byMatching: dc, startingAt: start,  matchingPolicy: .strict, repeatedTimePolicy: .last).makeIterator()
let result = sequenceIterator.next()
assert(result == expected)

when nanosecond is set to a value, enumeration always returns the 01:20 before the switch and the assertion fails.

The bug occurs in Calendar.dateAfterMatchingNanosecond(...) in Calendar_Enumerate.swift. This method simply returns a new date using Calendar.date(from: DateComponents), but in the test above there are two dates matching the components, and we need a way to specify if we want the first or second one.

@hristost
Copy link
Contributor Author

rdar://124640028

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

No branches or pull requests

1 participant