mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Show seconds in messages option (#99)
* Show seconds in messages option * Update SimpleSettings.swift
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import SGSimpleSettings
|
||||
import Foundation
|
||||
import TelegramPresentationData
|
||||
import TelegramUIPreferences
|
||||
@@ -46,8 +47,11 @@ public func stringForMessageTimestamp(timestamp: Int32, dateTimeFormat: Presenta
|
||||
} else {
|
||||
gmtime_r(&t, &timeinfo)
|
||||
}
|
||||
|
||||
return stringForShortTimestamp(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, dateTimeFormat: dateTimeFormat)
|
||||
if SGSimpleSettings.shared.secondsInMessages {
|
||||
return stringForShortTimestampWithSeconds(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, seconds: timeinfo.tm_sec, dateTimeFormat: dateTimeFormat)
|
||||
} else {
|
||||
return stringForShortTimestamp(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, dateTimeFormat: dateTimeFormat)
|
||||
}
|
||||
}
|
||||
|
||||
public func getDateTimeComponents(timestamp: Int32) -> (day: Int32, month: Int32, year: Int32, hour: Int32, minutes: Int32) {
|
||||
@@ -222,3 +226,38 @@ public func stringForDateWithoutDayAndMonth(date: Date, timeZone: TimeZone? = Ti
|
||||
formatter.setLocalizedDateFormatFromTemplate("yyyy")
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
public func stringForShortTimestampWithSeconds(hours: Int32, minutes: Int32, seconds: Int32, dateTimeFormat: PresentationDateTimeFormat) -> String {
|
||||
switch dateTimeFormat.timeFormat {
|
||||
case .regular:
|
||||
let hourString: String
|
||||
if hours == 0 {
|
||||
hourString = "12"
|
||||
} else if hours > 12 {
|
||||
hourString = "\(hours - 12)"
|
||||
} else {
|
||||
hourString = "\(hours)"
|
||||
}
|
||||
|
||||
let periodString: String
|
||||
if hours >= 12 {
|
||||
periodString = "PM"
|
||||
} else {
|
||||
periodString = "AM"
|
||||
}
|
||||
|
||||
let minuteString: String
|
||||
if minutes >= 10 {
|
||||
minuteString = "\(minutes)"
|
||||
} else {
|
||||
minuteString = "0\(minutes)"
|
||||
}
|
||||
if seconds >= 10 {
|
||||
return "\(hourString):\(minuteString):\(seconds)\u{00a0}\(periodString)"
|
||||
} else {
|
||||
return "\(hourString):\(minuteString):0\(seconds)\u{00a0}\(periodString)"
|
||||
}
|
||||
case .military:
|
||||
return String(format: "%02d:%02d:%02d", arguments: [Int(hours), Int(minutes), Int(seconds)])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user