mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Render the live location timeline item (#5209)
* created the data for the timeline item # Conflicts: # ElementX/Sources/Other/Logging/Tracing.swift # ElementX/Sources/Services/Authentication/AuthenticationService.swift # ElementX/Sources/Services/Authentication/LinkNewDeviceService.swift * Implemented the LLS timeline item * updated preview tests * pr and design suggestions * previewscrollview is debug only
This commit is contained in:
@@ -34,6 +34,25 @@ extension Date {
|
||||
}
|
||||
}
|
||||
|
||||
/// The date of an expiration formatted with the minimal necessary units given how long in the future it is.
|
||||
func formattedExpiration() -> String {
|
||||
let calendar = Calendar.current
|
||||
let now = Date.now
|
||||
|
||||
guard let tomorrow = calendar.date(byAdding: .hour, value: 24, to: now),
|
||||
let oneYearFromNow = calendar.date(byAdding: .year, value: 1, to: now) else {
|
||||
return formatted(date: .omitted, time: .shortened)
|
||||
}
|
||||
|
||||
if self < tomorrow {
|
||||
return formatted(date: .omitted, time: .shortened)
|
||||
} else if self < oneYearFromNow {
|
||||
return formatted(.dateTime.day().month())
|
||||
} else {
|
||||
return formatted(.dateTime.year())
|
||||
}
|
||||
}
|
||||
|
||||
/// Similar to ``formattedMinimal`` but returning "Today" instead of the time and
|
||||
/// including the year when it the date is from a previous year (rather than over a year ago).
|
||||
func formattedDateSeparator() -> String {
|
||||
@@ -60,6 +79,12 @@ extension Date {
|
||||
formatted(date: .omitted, time: .shortened)
|
||||
}
|
||||
|
||||
/// A fixed date representing today at 4:20 AM, used for mocks and previews.
|
||||
static var mockToday420: Date {
|
||||
// swiftlint:disable:next force_unwrap
|
||||
Calendar.current.date(bySettingHour: 4, minute: 20, second: 0, of: .now)!
|
||||
}
|
||||
|
||||
/// A fixed date used for mocks, previews etc.
|
||||
static var mock: Date {
|
||||
DateComponents(calendar: .current, year: 2007, month: 1, day: 9, hour: 9, minute: 41).date ?? .now
|
||||
|
||||
Reference in New Issue
Block a user