@@ -162,22 +162,25 @@ public class RelativeFormatter: DateToStringTrasformable {
162162 ///
163163 /// - Parameter locale: locale to load
164164 /// - Returns: language table
165- private func language( forLocale locale: Locale ) -> RelativeFormatterLang {
166- let localeId = ( locale. collatorIdentifier ?? Locales . english. toLocale ( ) . collatorIdentifier!)
167- guard let table = languagesCache [ localeId] else {
168- var tableType = languagesMap [ localeId]
169- if tableType == nil {
170- tableType = languagesMap [ localeId. components ( separatedBy: " - " ) . first!]
171- if tableType == nil {
172- return language ( forLocale: Locales . english. toLocale ( ) )
173- }
174- }
175- let instanceOfTable = tableType!. init ( )
176- languagesCache [ localeId] = instanceOfTable
177- return instanceOfTable
178- }
179- return table
180- }
165+ private func language( forLocale locale: Locale ) -> RelativeFormatterLang {
166+ let localeId = ( locale. collatorIdentifier ?? Locales . english. toLocale ( ) . collatorIdentifier!)
167+ guard let table = languagesCache [ localeId] else {
168+ var tableType = languagesMap [ localeId]
169+ if tableType == nil {
170+ tableType = languagesMap [ localeId. components ( separatedBy: " _ " ) . first!]
171+ if tableType == nil {
172+ tableType = languagesMap [ localeId. components ( separatedBy: " - " ) . first!]
173+ }
174+ if tableType == nil {
175+ return language ( forLocale: Locales . english. toLocale ( ) )
176+ }
177+ }
178+ let instanceOfTable = tableType!. init ( )
179+ languagesCache [ localeId] = instanceOfTable
180+ return instanceOfTable
181+ }
182+ return table
183+ }
181184
182185 /// Implementation of the protocol for DateToStringTransformable.
183186 public static func format( _ date: DateRepresentable , options: Any ? ) -> String {
@@ -238,7 +241,7 @@ public class RelativeFormatter: DateToStringTrasformable {
238241 amount = round ( amount / granularity) * granularity
239242 }
240243
241- let value : Double = - 1.0 * Double( elapsed. sign) * suitableRule. roundingStrategy. round ( amount)
244+ let value : Double = - 1.0 * Double( elapsed. sign) * suitableRule. roundingStrategy. roundValue ( amount)
242245 let formatString = relativeFormat ( locale: locale, flavour: flavour, value: value, unit: suitableRule. unit)
243246 return formatString. replacingOccurrences ( of: " {0} " , with: String ( Int ( abs ( value) ) ) )
244247 }
0 commit comments