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

Inconsistent Time Zone Formatting Between macOS and Static Linux SDK #5100

Open
barnard-b opened this issue Oct 10, 2024 · 1 comment
Open

Comments

@barnard-b
Copy link

When formatting a date with the EST time zone on macOS and the Static Linux SDK, the resulting date string is inconsistent between the two platforms.

macOS

Resolved Time Zone for EST is EST
It is now Thursday, October 10, 2024 at 3:32:23 PM GMT-05:00

Linux

Resolved Time Zone for EST is EST
It is now Thursday, October 10, 2024 at 4:32:23 PM Eastern Daylight Time

Swift: Apple Swift version 6.0.1 (swift-6.0.1-RELEASE) Target: arm64-apple-macosx15.0
Static Linux SDK: swift-6.0.1-RELEASE_static-linux-0.0.1
macOS: 15.0.1
Linux: Alma Linux 8.10

FoundationTest.swift

import Foundation

@main
struct App {
    static func main() async throws {
        let date = Date()
        let identifier = "EST"
        let timeZone = TimeZone(identifier: identifier)
        print("Resolved Time Zone for \(identifier) is " + (timeZone?.identifier ?? "Invalid"))
        
        let formatter = DateFormatter()
        formatter.locale = Locale(identifier: "en_US_POSIX")
        formatter.timeZone = timeZone
        formatter.dateStyle = .full
        formatter.timeStyle = .full
        
        let formatted = formatter.string(from: date)
        print("It is now \(formatted)")
    }
}

Package.swift

// swift-tools-version: 6.0

import PackageDescription

let package = Package(
    name: "FoundationTest",
    platforms: [
        .macOS(.v12)
    ],
    targets: [
        .executableTarget(name: "FoundationTest")
    ]
)

Build for Linux

xcrun --toolchain swift swift build --swift-sdk x86_64-swift-linux-musl

Build for macOS

xcrun --toolchain swift swift build
@barnard-b barnard-b changed the title Inconsistent Time Zone Formatting Between macOS and Linux Static SDK Inconsistent Time Zone Formatting Between macOS and Static Linux SDK Oct 10, 2024
@itingliu
Copy link
Contributor

There seems to be two separate issues here:

  1. A bug in Linux, where you've set the timezone to be EST, but the output is in EDT.
  2. Inconsistent behavior of the time zone representation: Linux is using the timezone identifier, but mac is using GMT offset. I think the full name is the expected behavior.

I do want to point out that this isn't 100% correct...

let identifier = "EST"
let timeZone = TimeZone(identifier: identifier)

"EST" isn't a valid time zone identifier. It's an abbreviation, so you should be using the other API, which reverse-look up the appropriate identifier for you

let timeZone = TimeZone(abbreviation:"EST") 

Using this would solve (2) and format EST as its full name.

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

2 participants