ISO8601
ISO8601 copied to clipboard
Use internal calendar for time zone changes
It's unsafe to adjust the shared reference [NSCalendar currentCalendar] without copying it. This also ensures changing locales does not affect how ISO dates get formatted, which we had come up in a bug report.
To reproduce:
- Open Settings > General > Language & Region.
- Change Calendar to Buddhist or Japanese.
- Run tests.
Could've sworn I read it's copy on write automatically. I can't find it now though.
Hmm, actually taking a second look at it, it seems that it's just copied everytime (but might be an implementation detail):
- https://github.com/apple/swift-corelibs-foundation/blob/a2904a2e617f4582879873326ede1d03ad3136fa/Foundation/Calendar.swift#L20
- https://github.com/nickhutchinson/CFLite/blob/d8fe813b4453a30ea9d8091bd19933e25f95f624/CoreFoundation/CFCalendar.c#L136
#import <Foundation/Foundation.h>
int main() {
NSLog(@"%p", [NSCalendar currentCalendar]);
NSLog(@"%p", [NSCalendar currentCalendar]);
}
./test
2016-09-27 10:27:59.412 test[84285:833759] 0x7ff2cb606c10
2016-09-27 10:27:59.413 test[84285:833759] 0x7ff2cb607640
This should be a performance improvement as well, then (might be worth benchmarking to compare before/after).