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-1325] NSDateFormatter doesn’t include prepositions in some languages #4158

Closed
alexito4 opened this issue Apr 26, 2016 · 10 comments
Closed

Comments

@alexito4
Copy link

Previous ID SR-1325
Radar None
Original Reporter @alexito4
Type Bug
Status Resolved
Resolution Done
Environment

swift-DEVELOPMENT-SNAPSHOT-2016-04-25-a-ubuntu14.04

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: c524d5eff4a7762650b51fce6fd5e43e

Issue Description:

Looks like NSDateFormatter doesn’t include prepositions in some languages.
For example using this code in the version of Swift included in Xcode 7.3 (using Apple NSFoundation) returns dimarts, 26 d’abril de 2016 in Catalan:

let f = NSDateFormatter()
f.locale = NSLocale(localeIdentifier: "ca")
f.dateStyle = .FullStyle
f.stringFromDate(NSDate())

Instead, using the open source foundation implementation it returns dimarts, 26 abril de 2016. (note the missing “d’” before the month).

let f = NSDateFormatter()
f.locale = NSLocale(localeIdentifier: "ca")
f.dateStyle = .FullStyle
f.string(from:NSDate())

dimarts, 26 d’abril de 2016
dimarts, 26 abril de 2016

@swift-ci
Copy link
Contributor

Comment by David Liu (JIRA)

     let f = DateFormatter()
     f.locale = Locale(identifier: "ca")
     f.dateStyle = .fullStyle
     let date = f.string(from: Date())

dimarts, 16 d’agost de 2016 //for today Aug 16
look like its working fine with the latest tip of Foundation master

@parkera can you also verify?

@alexito4
Copy link
Author

I just tried with Swift 3.0-PREVIEW-6 in ubuntu and the result seems the same.

./swift-3.0-PREVIEW-6-ubuntu14.04/usr/bin/swift test.swift
dissabte, 27 agost de 2016

with the code being updated to last the Swift 3 and Foundation changes:

let f = DateFormatter()
f.locale = Locale(localeIdentifier: "ca")
f.dateStyle = .fullStyle
let string = f.string(from: Date())
print(string)

@swift-ci
Copy link
Contributor

Comment by Steven Van Impe (JIRA)

I would also like to conform this issue.

Here is a test case:

import Foundation

extension Date {
    
    func formatted() -> String {
        let formatter = DateFormatter()
        formatter.locale = Locale(identifier: "nl_BE")
        formatter.timeZone = TimeZone(identifier: "Europe/Brussels")
        formatter.dateStyle = .full
        formatter.timeStyle = .short
        return formatter.string(from: self)
    }
}

let calendar = Calendar(identifier: .gregorian)
var dateComponents = DateComponents()
dateComponents.calendar = calendar
dateComponents.day = 22
dateComponents.month = 11
dateComponents.year = 1983
dateComponents.hour = 18
dateComponents.minute = 0
dateComponents.timeZone = TimeZone(identifier: "Europe/Brussels")
let date = calendar.date(from: dateComponents)!

print(date.formatted())

This prints "dinsdag 22 november 1983 om 18:00" on macOS and "dinsdag 22 november 1983 om 18:00" on Linux (Swift 4.1 on Ubuntu 14.04).

@spevans
Copy link
Collaborator

spevans commented Jan 15, 2019

Is this still an issue? The Linux builds now all use a later version of ICU which I believe is where the issue stemmed from.

$ cat sr-1325.swift 
import Foundation

func testDate(date: String, locale: String) {
    let f = DateFormatter()
    f.dateFormat = "yyyy-MM-dd"
    let d = f.date(from: date)!
    f.locale = Locale(identifier: locale)
    f.dateStyle = .full
    print("\(date), \(locale):", f.string(from: d))
}

testDate(date: "2016-04-26", locale: "ca")
testDate(date: "2016-08-16", locale: "ca")
testDate(date: "1983-11-22", locale: "nl_BE")
testDate(date: "1983-01-22", locale: "nl_BE")

Running with a master snapshot:

$ ~/swift-DEVELOPMENT-SNAPSHOT-2019-01-10-a-ubuntu18.04/usr/bin/swift sr-1325.swift 
2016-04-26, ca: dimarts, 26 dabril de 2016
2016-08-16, ca: dimarts, 16 dagost de 2016
1983-11-22, nl_BE: dinsdag 22 november 1983
1983-01-22, nl_BE: zaterdag 22 januari 1983

And with a swift-5.0 snapshot has the same output:

$ ~/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-01-10-a-ubuntu18.04/usr/bin/swift sr-1325.swift 
2016-04-26, ca: dimarts, 26 dabril de 2016
2016-08-16, ca: dimarts, 16 dagost de 2016
1983-11-22, nl_BE: dinsdag 22 november 1983
1983-01-22, nl_BE: zaterdag 22 januari 1983

@swift-ci
Copy link
Contributor

Comment by Steven Van Impe (JIRA)

With 4.2.1, I'm still having issues.

Can you try adding a time? If I format 1983/11/22 18:00 with dateStyle full and timeStyle short in locale nl_BE, I get "dinsdag 22 november 1983 om 18:00" on Mac but "dinsdag 22 november 1983 18:00" on Linux.

@spevans
Copy link
Collaborator

spevans commented Jan 15, 2019

$ cat nlbe.swift
import Foundation

func testDate(date: String, locale: String) {
 let f = DateFormatter()
 f.dateFormat = "yyyy-MM-dd HH:mm"
 let d = f.date(from: date)!
 f.locale = Locale(identifier: locale)
 f.dateStyle = .full
 f.timeStyle = .short
 print("\(date), \(locale):", f.string(from: d))
}

testDate(date: "1983-11-22 18:00", locale: "nl_BE")

Linux (ubuntu18.04)

# 4.2.1
$ ~/swift-4.2.1-RELEASE-ubuntu18.04/usr/bin/swift nlbe.swift
1983-11-22 18:00, nl_BE: dinsdag 22 november 1983 om 18:00

# 5.0
$ ~/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-01-10-a-ubuntu18.04/usr/bin/swift nlbe.swift
1983-11-22 18:00, nl_BE: dinsdag 22 november 1983 om 18:00

# master
$ ~/swift-DEVELOPMENT-SNAPSHOT-2019-01-10-a-ubuntu18.04/usr/bin/swift nlbe.swift
1983-11-22 18:00, nl_BE: dinsdag 22 november 1983 om 18:00

macOS Mojave

# 4.2.1
$ swift nlbe.swift
1983-11-22 18:00, nl_BE: dinsdag 22 november 1983 om 18:00

# 5.0
$ ~/Library/Developer/Toolchains/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-01-10-a.xctoolchain/usr/bin/swift nlbe.swift
1983-11-22 18:00, nl_BE: dinsdag 22 november 1983 om 18:00

# master
$ ~/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-01-10-a.xctoolchain/usr/bin/swift nlbe.swift
1983-11-22 18:00, nl_BE: dinsdag 22 november 1983 om 18:00

So every version gives the same output. Note that the output for 4.2.1 on Linux will depend on the version of Ubuntu that you are using as 16.04 and 14.04 have older versions of ICU.

So is the output correct here or is it wrong? They all seem to match so it would indicate an underlying ICU issue if it is still wrong.

@swift-ci
Copy link
Contributor

Comment by Steven Van Impe (JIRA)

I am using the Docker image, which uses 16.04, so I guess that explains the difference?

Would you mind taking a look at https://bugs.swift.org/browse/SR-9668 ? Is that one fixed in 18.04 as well?

@spevans
Copy link
Collaborator

spevans commented Jan 15, 2019

svanimpe (JIRA User) Which docker image are you using?

@swift-ci
Copy link
Contributor

Comment by Steven Van Impe (JIRA)

swift:4.2.1

@alexito4
Copy link
Author

The output in catalan looks good now. Thanks!

@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

3 participants