From e56a89e3edd3eb125c015863e8ac9bb413086f1a Mon Sep 17 00:00:00 2001 From: quadbyte Date: Mon, 11 Aug 2025 18:05:39 -0400 Subject: [PATCH] Timestamp in seconds (Epoch style) --- Services/Location.qml | 7 +++---- Services/Time.qml | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Services/Location.qml b/Services/Location.qml index fc79a67..3e97c7b 100644 --- a/Services/Location.qml +++ b/Services/Location.qml @@ -9,7 +9,7 @@ Singleton { id: root property string locationFile: Quickshell.env("NOCTALIA_WEATHER_FILE") || (Settings.cacheDir + "location.json") - property int weatherUpdateFrequency: 30 * 60 * 1000 // 30 minutes expressed in milliseconds + property int weatherUpdateFrequency: 30 * 60 // 30 minutes expressed in seconds property var data: adapter // Used to access via Location.data.xxx.yyy FileView { @@ -58,8 +58,7 @@ Singleton { // -------------------------------- function updateWeather() { - var now = Date.now() - if ((data.weatherLastFetch === "") || (now >= data.weatherLastFetch + weatherUpdateFrequency)) { + if ((data.weatherLastFetch === "") || (Time.timestamp >= data.weatherLastFetch + weatherUpdateFrequency)) { getFreshWeather() } } @@ -122,7 +121,7 @@ Singleton { // Save to json data.weather = weatherData - data.weatherLastFetch = Date.now() + data.weatherLastFetch = Time.timestamp console.log("Cached weather to disk") } catch (e) { errorCallback("Failed to parse weather data.") diff --git a/Services/Time.qml b/Services/Time.qml index 702e1b9..f277a5d 100644 --- a/Services/Time.qml +++ b/Services/Time.qml @@ -10,7 +10,7 @@ Singleton { property var date: new Date() property string time: Settings.data.location.use12HourClock ? Qt.formatDateTime(date, "h:mm AP") : Qt.formatDateTime( date, "HH:mm") - property string dateString: { + readonly property string dateString: { let now = date let dayName = now.toLocaleDateString(Qt.locale(), "ddd") dayName = dayName.charAt(0).toUpperCase() + dayName.slice(1) @@ -38,6 +38,11 @@ Singleton { + (Settings.data.location.reverseDayMonth ? `${month} ${day}${suffix} ${year}` : `${day}${suffix} ${month} ${year}`) } + // Returns a Unix Timestamp (in seconds) + readonly property string timestamp: { + return Math.floor(Date.now() / 1000); + } + // Format an easy to read approximate duration ex: 4h32m // Used to display the time remaining on the Battery widget function formatVagueHumanReadableDuration(totalSeconds) {