TeraViewerCalendarContext.swift (857B)
1 import Foundation 2 import TeraKitBindings 3 4 struct TeraViewerCalendarContext: Sendable, Equatable { 5 let asOfUnixSeconds: UInt64 6 let timeZoneID: String 7 let timeZone: TimeZone 8 let civilDate: TeraCivilDate 9 } 10 11 extension FfiViewerCalendarContext { 12 func appValue() throws -> TeraViewerCalendarContext { 13 guard schemaVersion == 1, asOfUnixS > 0, 14 TeraCalendarTiming.presentationInstant(asOfUnixS) != nil, 15 timeZone.utf8.count <= 255, let zone = TimeZone(identifier: timeZone) 16 else { throw TeraCalendarTiming.unsupported } 17 // Rust's pinned database owns the relevance date. Do not recalculate it 18 // with potentially different OS timezone rules at the native boundary. 19 return try TeraViewerCalendarContext( 20 asOfUnixSeconds: asOfUnixS, timeZoneID: timeZone, 21 timeZone: zone, civilDate: civilDate.appValue() 22 ) 23 } 24 }