let date = new Date(new Date().getFullYear(),11,31,23,59)
const now = new Date()
let hours = Math.round(((date - now)/1000)/3600)
let w = new ListWidget()
let title = w.addText("Hours left:")
title.font = Font.boldSystemFont(14)
title.centerAlignText()
let hourDisplay = w.addText(String(hours))
hourDisplay.font = Font.boldSystemFont(16)
hourDisplay.centerAlignText()
Script.setWidget(w)
Script.complete()
w.presentSmall()
let currentHours = currentFullDate.getHours() let currentMonth = currentFullDate.getMonth() let currentDay = currentFullDate.getDate() //The function is getDate, not getDay
let daysOfMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] // Now you have to consider the leap year where February has 29 days. But I’ll leave it to you :)
let leftHours = 24 - currentHours let leftMonths = 11 - currentMonth //because month here starts from 0 let leftDays = daysOfMonths[currentMonth] - currentDay
1
u/MrSecretPotato Jan 27 '25
What exactly is that you want?
3
u/gondouk Feb 01 '25
this will improve very soon with the introduction of Temporal
1
u/Grey_Mamba_371 Jan 27 '25
let currentFullDate = new Date();
let currentHours = currentFullDate.getHours() let currentMonth = currentFullDate.getMonth() let currentDay = currentFullDate.getDate() //The function is getDate, not getDay
let daysOfMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] // Now you have to consider the leap year where February has 29 days. But I’ll leave it to you :)
let leftHours = 24 - currentHours let leftMonths = 11 - currentMonth //because month here starts from 0 let leftDays = daysOfMonths[currentMonth] - currentDay
let totalHours = 0
for(let i=11; i>currentMonth; i—){ totalHours += daysOfMonths[i] * 24 }
totalHours += leftDays * 24
totalHours += leftHours
console.log(totalHours)
1
u/Available-Try149 Feb 04 '25
Does anyone have full guide how to set this up? Editing a widget and typing in the code doesn’t work
1
u/lilAnt0855 Nov 19 '25
whats his app named? I cant really see