[swift-users] DateFormatter bug
Ronaldo Faria Lima
ronaldo at nineteen.com.br
Mon May 15 18:53:30 CDT 2017
Hi, all.
During a discussion in CocoaHeads Brazil, one developer came with a very odd situation involving Foundation’s DateFormatter class. Here is the code:
import Foundation
let fmt = DateFormatter()
fmt.dateFormat = "yyyy-MM-dd"
let aDate = fmt.date(from: "2017-10-15”)
The variable aDate is becoming nil. In order to reproduce it, you will need to change the time zone to Americas/Sao_Paulo in your system. On other time zones, it works perfectly.
There is another important fact: 15 of October is when day light savings is effective in Brazil.
Debugging this, I have found that setting the calendar property, it works perfectly, which means that it possibly be a bug on Core Foundation (I found that DateFormatter, in fact, calls Core Foundation functions under the hood).
I’d like to know if you guys can reproduce it on other time zones that have a day light saving, for the day that it become effective.
Cheers!
Ronaldo Faria Lima
Nineteen
ronaldo at nineteen.com.br
+55 16 98136 5287
More information about the swift-users
mailing list