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

Iterator.rruleContext?.evaluateScript hangs with certain device date/time regional/locale settings #12

Open
simonbromberg opened this issue Apr 19, 2018 · 2 comments

Comments

@simonbromberg
Copy link

During unrelated testing of formatting time with the 12 hour / 24 hour time switch in iOS' Date & Time settings I noticed my app was hanging indefinitely, and I narrowed it down to this line in Iterators.swift:

guard let betweenOccurrences = Iterator.rruleContext?.evaluateScript("rule.between(new Date('\(beginDateJSON)'), new Date('\(untilDateJSON)'))").toArray() as? [Date] else {
    return []
}

Typically I set my device's region to United States, but I changed it to United Kingdom. Even then it was fine, but if I turned the use 24 hour time switch to off (in the UK it defaults to on), the app has this problem with hanging.

Regardless of how big the gap between the two dates are, it seems to always hang. Memory doesn't build up, no error… I haven't really left it sitting to see if it ever escapes.

I think it can be easily resolved by setting a locale on the ISO8601DateFormatter in RRule.swift, e.g.:

dateFormatter.locale = Locale(identifier: "en_US_POSIX")

It already sets the time zone to 0 seconds away from GMT so it seems it might as well prevent the locale of the device affecting the output.

I'm not clear on why it's doing this, but it might be because date formats are overridden by this "use 24 hour time" switch such according to whatever the default is for that region. So in the US the default is 12 hour time, so if you have a date format like "hh:mm a" then it will replace it with "HH:mm" if the switch is on. If you have a date format like "HH:mm" it seems to keep it as 24 hour time if your region's default is 12 hour time. But if your region defaults to 24 hour time, it looks like it might be the other way around. So if your format is "hh:mm a" it will not replace it, but if it's "HH:mm" then it will if the switch is turned off. I haven't tested this theory fully, but it seems to make sense.

@simonbromberg simonbromberg changed the title Iterator.rruleContext?.evaluateScript hangs with certain device date/time settings Iterator.rruleContext?.evaluateScript hangs with certain device date/time regional/locale settings Apr 19, 2018
@simonbromberg
Copy link
Author

Made changes in this fork https://github.com/simonbromberg/RRuleSwift, seems to be working, just trying to verify there aren't any side effects.

I also have the Cocoapods PR merged in there.

@simonbromberg
Copy link
Author

simonbromberg commented Apr 19, 2018

Also just noticed there is a ISO8601DateFormatter built into iOS as of iOS 10.

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