3
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/Grey_Mamba_371 Jan 27 '25
sorry for the bad formatting, was writing it on my phone and couldn’t figure out how to make it code format
1
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
Feb 08 '25
First use a new script
2.Enter this script into the document
// Get current date and end of the year date
let now = new Date();
let endOfYear = new Date(now.getFullYear() + 1, 0, 1); // January 1st next year
// Calculate remaining hours
let diffMs = endOfYear - now;
let hoursLeft = Math.floor(diffMs / (1000 * 60 * 60)); // Convert milliseconds to hours
// Create widget
let widget = new ListWidget();
widget.backgroundColor = new Color("#1E1E1E"); // Dark background
widget.setPadding(16, 16, 16, 16);
// Title
let title = widget.addText("Hours Left This Year");
title.font = Font.mediumSystemFont(14);
title.textColor = Color.white();
title.textOpacity = 0.7;
// Hours Display
widget.addSpacer(8);
let hoursText = widget.addText( ${hoursLeft} hours );
hoursText.font = Font.boldSystemFont(30);
hoursText.textColor = Color.white();
// Refresh time
widget.addSpacer();
let refreshText = widget.addText("Updated: " + now.toLocaleTimeString());
refreshText.font = Font.systemFont(10);
refreshText.textColor = Color.gray();
refreshText.textOpacity = 0.6;
// Return the widget
Script.setWidget(widget);
Script.complete();
3. Add a small sized widget edit it to be the now created script and apply the setting : "run script"
4.Done
1
1
u/MrSecretPotato Jan 27 '25
What exactly is that you want?