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

weekdayName(), eraName(), quarterName() allows to specify locale overwrite to region's locale #521

Closed
Pr-Chen opened this issue Dec 29, 2017 · 1 comment
Assignees
Milestone

Comments

@Pr-Chen
Copy link

Pr-Chen commented Dec 29, 2017

My iPhone's language is Chinese, but when I run this code, weekdayName is english

guard let date = @"2017-12-29".date(format: .custom("yyyy-MM-dd"), fromRegion: Region.Local()) else {
    return
}

// name is Fri, but I expect is 周五
var name = date.weekdayShortName
@malcommac
Copy link
Owner

malcommac commented Oct 26, 2018

Since SwiftDate 5.x you can use weekDayName function and you can override the current locale of the date (>=5.12):

let region = Region(calendar: Calendars.gregorian, zone: Zones.europeLondon, locale: Locales.chinese)
let date = "2017-12-29".toDate("yyyy-MM-dd", region: region)
let string = date?.weekdayName(.short, locale: Locales.english) // you can specify the output locale directly

@malcommac malcommac changed the title Region.Local() is based on the device language to determine it? weekdayName(), eraName(), quarterName() can now specify locale overwrite to region's locale Oct 26, 2018
@malcommac malcommac self-assigned this Oct 26, 2018
@malcommac malcommac added this to the 5.0.12 milestone Oct 26, 2018
@malcommac malcommac changed the title weekdayName(), eraName(), quarterName() can now specify locale overwrite to region's locale weekdayName(), eraName(), quarterName() allows to specify locale overwrite to region's locale Oct 26, 2018
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

2 participants