Various improvements

This commit is contained in:
Ilya Laktyushin
2024-03-21 01:12:21 +04:00
parent 390a5e6376
commit 350e9bdc10
7 changed files with 94 additions and 47 deletions

View File

@@ -146,24 +146,13 @@ public func stringForCompactDate(timestamp: Int32, strings: PresentationStrings,
return "\(shortStringForDayOfWeek(strings: strings, day: timeinfo.tm_wday)) \(timeinfo.tm_mday) \(monthAtIndex(Int(timeinfo.tm_mon), strings: strings))"
}
public func stringForCompactBirthday(_ birthday: TelegramBirthday, strings: PresentationStrings) -> String {
public func stringForCompactBirthday(_ birthday: TelegramBirthday, strings: PresentationStrings, showAge: Bool = false) -> String {
var components: [String] = []
components.append("\(birthday.day)")
components.append(monthAtIndex(Int(birthday.month) - 1, strings: strings))
if let year = birthday.year {
components.append("\(year)")
}
return components.joined(separator: " ")
}
public func stringForFullBirthday(_ birthday: TelegramBirthday, strings: PresentationStrings, showAge: Bool = false) -> String {
var components: [String] = []
components.append("\(birthday.day)")
components.append(stringForMonth(strings: strings, month: birthday.month - 1))
if let year = birthday.year {
components.append("\(year)")
if showAge {
var dateComponents = DateComponents()
dateComponents.day = Int(birthday.day)
@@ -173,7 +162,7 @@ public func stringForFullBirthday(_ birthday: TelegramBirthday, strings: Present
let calendar = Calendar.current
if let birthDate = calendar.date(from: dateComponents) {
if let age = calendar.dateComponents([.year], from: birthDate, to: Date()).year {
components.append("(\(age))")
components.append("(\(strings.UserInfo_Age(Int32(age))))")
}
}
}