summaryrefslogtreecommitdiffstats
path: root/Solsnu.Widget/Models/SolsticeEvent.swift
diff options
context:
space:
mode:
authorivar <i@oiee.no>2026-03-23 16:47:59 +0100
committerivar <i@oiee.no>2026-03-23 16:47:59 +0100
commit94bf65b7e6b0cb683ea9c952aed86b034d1c8363 (patch)
tree6158072e01f9ffe2dd8754e9b136f8978bb11d6e /Solsnu.Widget/Models/SolsticeEvent.swift
parente45dd001f178a640e1f799616868accb4254c313 (diff)
downloadsolverv-94bf65b7e6b0cb683ea9c952aed86b034d1c8363.tar.xz
solverv-94bf65b7e6b0cb683ea9c952aed86b034d1c8363.zip
feat: implement SolvervDef methods and update widget timeline to refresh at midnight
Diffstat (limited to 'Solsnu.Widget/Models/SolsticeEvent.swift')
-rw-r--r--Solsnu.Widget/Models/SolsticeEvent.swift38
1 files changed, 38 insertions, 0 deletions
diff --git a/Solsnu.Widget/Models/SolsticeEvent.swift b/Solsnu.Widget/Models/SolsticeEvent.swift
new file mode 100644
index 0000000..d8c4a7b
--- /dev/null
+++ b/Solsnu.Widget/Models/SolsticeEvent.swift
@@ -0,0 +1,38 @@
+import Foundation
+
+struct SolsticeEvent: Identifiable, Codable {
+ let id: UUID
+ let name: String
+ let date: Date // UTC
+ let season: Season
+
+ init(name: String, date: Date, season: Season) {
+ self.id = UUID()
+ self.name = name
+ self.date = date
+ self.season = season
+ }
+
+ /// Convert UTC date to user's local timezone
+ func localDateTime() -> Date {
+ let utcCalendar = Calendar(identifier: .gregorian)
+ let utcComponents = utcCalendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date)
+ let timeZone = TimeZone.current
+ let offset = timeZone.secondsFromGMT(for: date)
+
+ var localCalendar = Calendar.current
+ localCalendar.timeZone = timeZone
+ var localComponents = utcComponents
+ localComponents.second = (localComponents.second ?? 0) + offset
+
+ return localCalendar.date(from: localComponents) ?? date
+ }
+
+ /// Days until this event from today
+ func daysUntil() -> Int {
+ let today = Calendar.current.startOfDay(for: Date())
+ let eventDay = Calendar.current.startOfDay(for: date)
+ let components = Calendar.current.dateComponents([.day], from: today, to: eventDay)
+ return max(0, components.day ?? 0)
+ }
+}