Timestamp in seconds (Epoch style)

This commit is contained in:
quadbyte 2025-08-11 18:05:39 -04:00
parent 644f647653
commit e56a89e3ed
2 changed files with 9 additions and 5 deletions

View file

@ -9,7 +9,7 @@ Singleton {
id: root id: root
property string locationFile: Quickshell.env("NOCTALIA_WEATHER_FILE") || (Settings.cacheDir + "location.json") 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 property var data: adapter // Used to access via Location.data.xxx.yyy
FileView { FileView {
@ -58,8 +58,7 @@ Singleton {
// -------------------------------- // --------------------------------
function updateWeather() { function updateWeather() {
var now = Date.now() if ((data.weatherLastFetch === "") || (Time.timestamp >= data.weatherLastFetch + weatherUpdateFrequency)) {
if ((data.weatherLastFetch === "") || (now >= data.weatherLastFetch + weatherUpdateFrequency)) {
getFreshWeather() getFreshWeather()
} }
} }
@ -122,7 +121,7 @@ Singleton {
// Save to json // Save to json
data.weather = weatherData data.weather = weatherData
data.weatherLastFetch = Date.now() data.weatherLastFetch = Time.timestamp
console.log("Cached weather to disk") console.log("Cached weather to disk")
} catch (e) { } catch (e) {
errorCallback("Failed to parse weather data.") errorCallback("Failed to parse weather data.")

View file

@ -10,7 +10,7 @@ Singleton {
property var date: new Date() property var date: new Date()
property string time: Settings.data.location.use12HourClock ? Qt.formatDateTime(date, "h:mm AP") : Qt.formatDateTime( property string time: Settings.data.location.use12HourClock ? Qt.formatDateTime(date, "h:mm AP") : Qt.formatDateTime(
date, "HH:mm") date, "HH:mm")
property string dateString: { readonly property string dateString: {
let now = date let now = date
let dayName = now.toLocaleDateString(Qt.locale(), "ddd") let dayName = now.toLocaleDateString(Qt.locale(), "ddd")
dayName = dayName.charAt(0).toUpperCase() + dayName.slice(1) 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}`) + (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 // Format an easy to read approximate duration ex: 4h32m
// Used to display the time remaining on the Battery widget // Used to display the time remaining on the Battery widget
function formatVagueHumanReadableDuration(totalSeconds) { function formatVagueHumanReadableDuration(totalSeconds) {