Skip to content

Commit bb9c234

Browse files
committed
Fix formater for date. Add serif to font
1 parent ee228ce commit bb9c234

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Sources/SparrowKit/Foundation/DateExtensions.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,14 @@ public extension Date {
206206
DateFormatter.localizedString(from: self, dateStyle: dateStyle, timeStyle: timeStyle)
207207
}
208208

209-
func formatted(as format: String = "dd.MM.yyyy HH:mm") -> String {
209+
func formatted(as format: String = "dd.MM.yyyy HH:mm", localized: Bool) -> String {
210210
let dateFormatter = DateFormatter()
211-
dateFormatter.dateFormat = format
211+
dateFormatter.locale = Locale.current
212+
if localized {
213+
dateFormatter.setLocalizedDateFormatFromTemplate(format)
214+
} else {
215+
dateFormatter.dateFormat = format
216+
}
212217
return dateFormatter.string(from: self)
213218
}
214219

Sources/SparrowKit/UIKit/Extensions/UIFontExtensions.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public extension UIFont {
4444
}
4545
}
4646

47+
var serif: UIFont {
48+
if #available(iOS 13, tvOS 13, *) {
49+
guard let descriptor = fontDescriptor.withDesign(.serif) else { return self }
50+
return UIFont(descriptor: descriptor, size: 0)
51+
} else {
52+
return self
53+
}
54+
}
55+
4756
static func preferredFont(forTextStyle style: TextStyle, addPoints: CGFloat = 0) -> UIFont {
4857
let referensFont = UIFont.preferredFont(forTextStyle: style)
4958
return referensFont.withSize(referensFont.pointSize + addPoints)

0 commit comments

Comments
 (0)