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

Enable custom patterns #33

Open
Blackjacx opened this issue Oct 9, 2023 · 0 comments
Open

Enable custom patterns #33

Blackjacx opened this issue Oct 9, 2023 · 0 comments

Comments

@Blackjacx
Copy link
Owner

Blackjacx commented Oct 9, 2023

Actual behaviour

Right now one project that uses SHDateFormatter has a format that defines a special order of date components in SHDateformatter+Extensions.swift, like:

let weekdayString = string(from: date, format: .shortWeekday, timeZone: timeZone)
let dateString = string(from: date, format: .noTimeShortDateNoYear, timeZone: timeZone)
let timeString = string(from: date, format: .shortTimeNoDate, timeZone: timeZone)
return weekdayString + ", " + dateString + " - " + timeString

This doesn't work in other languages like Arabic.

Expected behaviour

For these cases Apple has defined a method that uses template date format strings and changes (reorders) them for the specified language. To make that work we have to either add a custom date format to SHDateFormatter which takes a string OR put that special date format in the enum and handle the custom format in SHDateFormatter, like:

case .shortWeekday, .longWeekday, .shortMonth, .longMonth, .longYear, .shortYear, .noTimeShortDateNoYear,
.shortYearMonth, .longYearMonth:
SHDateFormatter.formatter.dateFormat = DateFormatter.dateFormat(fromTemplate: format.rawValue,
options: 0,
locale: locale)

I guess the latter is the better option!

Don't forget to update the tests…

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

1 participant