Open swift-ci opened 5 years ago
@swift-ci create
If the format is set via the dateFormat
property then it works correctly, however when using the template 'y'
the date format used is 'G y'
where G
is the era 'AD' or 'BC' etc - see http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
Note the .dateFormat
property is how https://nsdateformatter.com/ works.
$ cat 11775.swift
import Foundation
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "ps")
dateFormatter.dateFormat = "y"
print("Using 'y':", dateFormatter.string(from: Date()))
dateFormatter.setLocalizedDateFormatFromTemplate("y")
let format = dateFormatter.dateFormat!
print("Template 'y' give dateFormat: \(format)")
print("Using '\(format)':", dateFormatter.string(from: Date()))
$ swift 11775.swift
Using 'y': ۱۳۹۸
Template 'y' give dateFormat: G y
Using 'G y': AP ۱۳۹۸
So the era is probably still incorrect although this is handled by the underlying ICU library
Comment by Petr Kubista (JIRA)
I believe I originally discovered this when using the following:
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
Environment
Tested in Xcode 11.1 with Swift 5Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: d7faf79af167c9fe80a07f4bf22e38c9Issue Description:
Using a simple code snippet, I can demonstrate that the year returned from DateFormatter when using Pashto locale is incorrect.
The value of yearString is:
"AP ۱۳۹۸"
Expected output (as seen for example here: https://nsdateformatter.com/):
"۲۰۱۹"