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-11775] DateFormatter returns incorrect year in Pashto #3375

Open
swift-ci opened this issue Nov 13, 2019 · 3 comments
Open

[SR-11775] DateFormatter returns incorrect year in Pashto #3375

swift-ci opened this issue Nov 13, 2019 · 3 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-11775
Radar rdar://problem/57176798
Original Reporter kubista.cameloit (JIRA User)
Type Bug
Environment

Tested in Xcode 11.1 with Swift 5

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

md5: d7faf79af167c9fe80a07f4bf22e38c9

Issue Description:

Using a simple code snippet, I can demonstrate that the year returned from DateFormatter when using Pashto locale is incorrect.

let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "ps")
dateFormatter.setLocalizedDateFormatFromTemplate("y")
let yearString = dateFormatter.string(from: Date())

The value of yearString is:

"AP ۱۳۹۸"

Expected output (as seen for example here: https://nsdateformatter.com/):

"۲۰۱۹"

@beccadax
Copy link
Contributor

@swift-ci create

@spevans
Copy link
Collaborator

spevans commented Feb 20, 2020

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

@swift-ci
Copy link
Contributor Author

Comment by Petr Kubista (JIRA)

I believe I originally discovered this when using the following:

let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium

@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
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