Skip to content

Commit

Permalink
#521 weekdayName(), quarterName() and eraName() now accepts locale ov…
Browse files Browse the repository at this point in the history
…erwrites
  • Loading branch information
malcommac committed Oct 26, 2018
1 parent ddcb5c5 commit 47aa6c9
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Sources/SwiftDate/DateRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public protocol DateRepresentable {
/// Name of the weekday expressed in given format style.
///
/// - Parameter style: style to express the value.
/// - Parameter locale: locale to use; ignore it to use default's region locale.
/// - Returns: weekday name
func weekdayName(_ style: SymbolFormatStyle) -> String
func weekdayName(_ style: SymbolFormatStyle, locale: LocaleConvertible?) -> String

/// Week of a year of the receiver.
var weekOfYear: Int { get }
Expand Down Expand Up @@ -95,17 +96,19 @@ public protocol DateRepresentable {
/// Quarter name expressed in given format style.
///
/// - Parameter style: style to express the value.
/// - Parameter locale: locale to use; ignore it to use default's region locale.
/// - Returns: quarter name
func quarterName(_ style: SymbolFormatStyle) -> String
func quarterName(_ style: SymbolFormatStyle, locale: LocaleConvertible?) -> String

/// Era value of the receiver.
var era: Int { get }

/// Name of the era expressed in given format style.
///
/// - Parameter style: style to express the value.
/// - Parameter locale: locale to use; ignore it to use default's region locale.
/// - Returns: era
func eraName(_ style: SymbolFormatStyle) -> String
func eraName(_ style: SymbolFormatStyle, locale: LocaleConvertible?) -> String

/// The current daylight saving time offset of the represented date.
var DSTOffset: TimeInterval { get }
Expand Down Expand Up @@ -376,8 +379,10 @@ public extension DateRepresentable {
return self.dateComponents.weekday!
}

func weekdayName(_ style: SymbolFormatStyle) -> String {
let formatter = self.formatter(format: nil)
func weekdayName(_ style: SymbolFormatStyle, locale: LocaleConvertible? = nil) -> String {
let formatter = self.formatter(format: nil) {
$0.locale = (locale ?? self.region.locale).toLocale()
}
let idx = (self.weekday - 1)
switch style {
case .default: return formatter.weekdaySymbols[idx]
Expand Down Expand Up @@ -442,8 +447,10 @@ public extension DateRepresentable {
return self.date > Date()
}

func quarterName(_ style: SymbolFormatStyle) -> String {
let formatter = self.formatter(format: nil)
func quarterName(_ style: SymbolFormatStyle, locale: LocaleConvertible? = nil) -> String {
let formatter = self.formatter(format: nil) {
$0.locale = (locale ?? self.region.locale).toLocale()
}
let idx = (self.quarter - 1)
switch style {
case .default: return formatter.quarterSymbols[idx]
Expand All @@ -457,8 +464,10 @@ public extension DateRepresentable {
return self.dateComponents.era!
}

func eraName(_ style: SymbolFormatStyle) -> String {
let formatter = self.formatter(format: nil)
func eraName(_ style: SymbolFormatStyle, locale: LocaleConvertible? = nil) -> String {
let formatter = self.formatter(format: nil) {
$0.locale = (locale ?? self.region.locale).toLocale()
}
let idx = (self.era - 1)
switch style {
case .default, .defaultStandalone: return formatter.longEraSymbols[idx]
Expand Down

0 comments on commit 47aa6c9

Please sign in to comment.