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
Comments
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 @parkera can you also verify? |
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 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) |
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). |
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 $ ~/swift-DEVELOPMENT-SNAPSHOT-2019-01-10-a-ubuntu18.04/usr/bin/swift sr-1325.swift
2016-04-26, ca: dimarts, 26 d’abril de 2016
2016-08-16, ca: dimarts, 16 d’agost 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-DEVELOPMENT-SNAPSHOT-2019-01-10-a-ubuntu18.04/usr/bin/swift sr-1325.swift
2016-04-26, ca: dimarts, 26 d’abril de 2016
2016-08-16, ca: dimarts, 16 d’agost de 2016
1983-11-22, nl_BE: dinsdag 22 november 1983
1983-01-22, nl_BE: zaterdag 22 januari 1983 |
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. |
$ 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. |
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? |
svanimpe (JIRA User) Which docker image are you using? |
Comment by Steven Van Impe (JIRA) swift:4.2.1 |
The output in catalan looks good now. Thanks! |
Environment
swift-DEVELOPMENT-SNAPSHOT-2016-04-25-a-ubuntu14.04
Additional Detail from JIRA
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:
Instead, using the open source foundation implementation it returns dimarts, 26 abril de 2016. (note the missing “d’” before the month).
dimarts, 26 d’abril de 2016
dimarts, 26 abril de 2016
The text was updated successfully, but these errors were encountered: