r/Scriptable • • Jan 27 '25

Help hours left in the year

Post image
11 Upvotes

21 comments sorted by

1

u/MrSecretPotato Jan 27 '25

What exactly is that you want?

2

u/Illumminouss Jan 27 '25

the widget saying how many hours left in the year with the text hours left above it. in the exact same format as the image 

2

u/mvan231 script/widget helper Jan 27 '25

Here you are:

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()

1

u/Illumminouss Jan 27 '25

how do i make it transparent?

1

u/mvan231 script/widget helper Jan 28 '25

That would require usage of another script like noBackground but it's a bit of a pain to setup because of needing screenshots of your wallpaper

1

u/Illumminouss Jan 28 '25

ive got the screenshot or my wallpaper but i dont know how to apply it to my widget. if you dont mind can you tell me. ill do it myself

1

u/mvan231 script/widget helper Jan 28 '25

Here is the details on how to install the script and set it up

https://github.com/supermamon/scriptable-no-background

→ More replies (4)

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/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

u/Illumminouss Jan 27 '25

its alright nws

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/[deleted] Feb 08 '25
  1. 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

u/lilAnt0855 Nov 19 '25

whats his app named? I cant really see