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
[SR-3298] Initializing TimeZone with Identifier results in wrong type/kind. #4437
Comments
Comment by aaron crespo (JIRA) Additionally: this behavior is different from Calendar fixed and Calendar current and Locale fixed and Locale current. which is why I thought it was unexpected. |
Comment by aaron crespo (JIRA) After looking at the source code it appears this might be intentional, however I think the difference in behavior between Locale, Calendar, Timezone, and equality is not documented. Locale from identifier is never equal to Locale current, same as Calendar from identifier and Calendar current, but sometimes Timezone from identifier is equal to Timezone current. It makes sense to me that a captured current Locale can be equal to a specific instance of a Locale. In which case Timezone is correct but Locale, and Calendar have the different/unexpected behavior, |
Comment by aaron crespo (JIRA) @parkera thoughts? |
The above output does make sense to me, because what it's saying is that ftimezone == the current time zone. I think the output of the debug description could use some improvement however. I wanted the equality and updating behavior of these three types to be the same. It sounds to me like a bug if the current Calendar can never be equal to a Calendar from an identifier (if other properties are equal). Same for Locale. |
I do also want to note that the autoupdating version of these three can only ever be equal to another autoupdating instance of the same type. |
Comment by aaron crespo (JIRA) Yeah after digging into the code I could see it being a difference in behavior between calendar/locale and timezone. Since timezone is the odd man out I thought it was culprit. > Calendar can never be equal to a Calendar from an identifier (if other properties are equal). Same for Locale. I just verified that this is the case let me know if I missed anything import Foundation
let ccurrent = Calendar.current
dump(ccurrent)
let acurrent = Calendar.autoupdatingCurrent
dump(acurrent)
let fcurrent = Calendar(identifier: .gregorian)
dump(fcurrent)
print(ccurrent == acurrent)
print(ccurrent == fcurrent)
//output:
▿ gregorian (current)
- identifier: Foundation.Calendar.Identifier.gregorian
- kind: "current"
▿ locale: Optional(en_US (current))
▿ some: en_US (current)
- identifier: "en_US"
- kind: "current"
▿ timeZone: America/New_York (current)
- identifier: "America/New_York"
- kind: "current"
▿ abbreviation: Optional("EST")
- some: "EST"
- secondsFromGMT: -18000
- isDaylightSavingTime: false
- firstWeekday: 1
- minimumDaysInFirstWeek: 1
▿ gregorian (autoupdatingCurrent)
- identifier: Foundation.Calendar.Identifier.gregorian
- kind: "autoupdatingCurrent"
▿ locale: Optional(en_US (current))
▿ some: en_US (current)
- identifier: "en_US"
- kind: "current"
▿ timeZone: America/New_York (current)
- identifier: "America/New_York"
- kind: "current"
▿ abbreviation: Optional("EST")
- some: "EST"
- secondsFromGMT: -18000
- isDaylightSavingTime: false
- firstWeekday: 1
- minimumDaysInFirstWeek: 1
▿ gregorian (fixed)
- identifier: Foundation.Calendar.Identifier.gregorian
- kind: "fixed"
▿ locale: Optional( (fixed))
▿ some: (fixed)
- identifier: ""
- kind: "fixed"
▿ timeZone: America/New_York (current)
- identifier: "America/New_York"
- kind: "current"
▿ abbreviation: Optional("EST")
- some: "EST"
- secondsFromGMT: -18000
- isDaylightSavingTime: false
- firstWeekday: 1
- minimumDaysInFirstWeek: 1
false
false Commenting out // lhs.locale == rhs.locale Produces the expected result in Calendar but should be fixed on Locale. Shall I edit this ticket or close/open a new one? looks like the issue is Locale's Equality since it propagates Calendar and not Timezone. |
We can use this ticket, since it's got the history in it. |
Comment by aaron crespo (JIRA) @parkera so I don't think there is an issue here For reference: let ccurrent = Calendar.current
var fcurrent = Calendar(identifier: Calendar.current.identifier)
fcurrent.locale = ccurrent.locale
XCTAssertEqual(ccurrent, fcurrent) // passes Behaves as expected. |
Yes I agree that Calendar locale should be part of equality. |
Environment
Swift 3.0.1 Xcode Version 8.2
Additional Detail from JIRA
md5: b1c50b35a172a505428c7f4d999bdc1a
Issue Description:
Initializing a TimeZone by identifier with an identifier matching the user's current timezone results in an unexpected TimeZone kind.
input:
output:
expected output:
The text was updated successfully, but these errors were encountered: