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

[SR-5596] TimeZone.current returns wrong value #4419

Closed
swift-ci opened this issue Jul 31, 2017 · 3 comments
Closed

[SR-5596] TimeZone.current returns wrong value #4419

swift-ci opened this issue Jul 31, 2017 · 3 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-5596
Radar None
Original Reporter bubski (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.12.6
Ubuntu 14.04
swift-DEVELOPMENT-SNAPSHOT-2017-07-26-a

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @spevans
Priority Medium

md5: 5d94b02b07b6ba6083a14aadb1ff4fbb

relates to:

  • SR-5598 TimeZone.current == TimeZone(identifier: TimeZone.current.identifier) fails on Linux

Issue Description:

TimeZone.current returns wrong GMT0 value.

▿ GMT (current)
  - identifier: "GMT"
  - kind: "current"
  ▿ abbreviation: Optional("GMT")
    - some: "GMT"
  - secondsFromGMT: 0
  - isDaylightSavingTime: false

Tested on both macOS 10.12.6 where Darwin's Foundation TimeZone.current returns

▿ Europe/Stockholm (current)
  - identifier: "Europe/Stockholm"
  - kind: "current"
  ▿ abbreviation: Optional("GMT+2")
    - some: "GMT+2"
  - secondsFromGMT: 7200
  - isDaylightSavingTime: true

and Ubuntu 14.04 where cat /etc/timezone returns

Europe/Stockholm

================

It appears that __CFTimeZoneCreateSystem fails all the way down to the last fallback CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorSystemDefault, 0.0);
at https://github.com/apple/swift-corelibs-foundation/blob/master/CoreFoundation/NumberDate.subproj/CFTimeZone.c#L816

@spevans
Copy link
Collaborator

spevans commented Aug 8, 2017

Hopefully this PR should fix it: #1163

It was broken in #1126

@swift-ci
Copy link
Contributor Author

Comment by Joseph Lawson (JIRA)

I meant to close SR-5598, this is still an issue on Linux

@spevans
Copy link
Collaborator

spevans commented Apr 26, 2019

This looks to be fixed now, note that the timezone should come from /etc/localtime, /etc/timezone is used to setup the link.

$ ls -l /etc/localtime 
lrwxrwxrwx 1 root root 36 Apr 26 12:49 /etc/localtime -> /usr/share/zoneinfo/Europe/Stockholm

$ cat sr-5596.swift 
import Foundation
print(TimeZone.current)

$ ~/swift-5.0-RELEASE-ubuntu18.04/usr/bin/swift sr-5596.swift 
Europe/Stockholm (current)

$ TZ=America/New_York ~/swift-5.0-RELEASE-ubuntu18.04/usr/bin/swift sr-5596.swift 
America/New_York (current)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants