Although this is just a small space script, I thought I will share it since it may be appealing for some of us who want to make the most of our time by being constantly aware of it.
This space script creates a visual progress bar indicating the time left in the day
How it looks:
The script:
silverbullet.registerFunction("timeLeftInDayWithBar", () => {
const now = Temporal.Now.zonedDateTimeISO('America/New_York');
const endOfDay = now.add({ days: 1 }).with({ hour: 0, minute: 0, second: 0, millisecond: 0, microsecond: 0, nanosecond: 0 });
const diff = now.until(endOfDay);
const totalSecondsInDay = 24 * 60 * 60; // Total seconds in a day
const remainingSeconds = diff.total('seconds');
const percentageLeft = (remainingSeconds / totalSecondsInDay) * 100;
const hours = diff.hours;
const minutes = diff.minutes;
const formattedTime = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
// Create the progress bar
const progressBarLength = 20; // Number of characters in the bar
const filledBarLength = Math.round((percentageLeft / 100) * progressBarLength);
const filledBar = "█".repeat(filledBarLength);
const emptyBar = "░".repeat(progressBarLength - filledBarLength);
const progressBar = `[${filledBar}${emptyBar}]`;
return `${formattedTime} ${progressBar} (${percentageLeft.toFixed(1)}%)`;
});
Note: you have to change the time zone inside the Temporal.Now.zonedDateTimeISO() to match yours by selecting from this list
I usually have SilverBullet open in the background as I work, and I have this script called on my index page like so, as a template:
✨ Today: **{{today()}}**
🕑 Time Left: **{{timeLeftInDayWithBar()}}**
Limitation: It will only refresh when the template gets rendered again
Future Scope: Could be extended to work as a progress bar indicating time left to finish a project/meet some deadline
Disclaimer: This script was generated using a language model, I have little to no experience with Javascript
Sharing a similar script to show a progress bar for time left till deadline for a project/task.
This space script creates a visual progress bar indicating the time left from given start date & time to end date & time
How it looks:
The script:
silverbullet.registerFunction("timeLeftUntil", (startDateTime, targetDateTime) => {
const timeZone = 'America/New_York'
const target = Temporal.ZonedDateTime.from(`${targetDateTime}[${timeZone}]`);
const start = Temporal.ZonedDateTime.from(`${startDateTime}[${timeZone}]`);
// Get the current time in the timezone
const now = Temporal.Now.zonedDateTimeISO(timeZone);
// Calculate the difference between now and the target time
const diff = now.until(target);
// Calculate the total duration in seconds
const totalSeconds = diff.total('seconds');
// Calculate the total duration from start to the target in seconds
const totalDuration = target.epochSeconds - start.epochSeconds;
// Calculate the percentage of time left
const percentageLeft = Math.max(0, Math.min(100, (totalSeconds / totalDuration) * 100));
// Extract hours and minutes from the difference
const hours = diff.hours;
const minutes = diff.minutes;
// Format the time as HH:MM
const formattedTime = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
// Create the progress bar
const progressBarLength = 20; // Number of characters in the bar
const filledBarLength = Math.round((percentageLeft / 100) * progressBarLength);
const filledBar = "█".repeat(Math.max(0, filledBarLength)); // Ensure non-negative length
const emptyBar = "░".repeat(Math.max(0, progressBarLength - filledBarLength)); // Ensure non-negative length
const progressBar = `[${filledBar}${emptyBar}]`;
// Return the formatted time, progress bar, and percentage left
return `${formattedTime} ${progressBar} (${percentageLeft.toFixed(1)}%)`;
});
This is how I call it on my index page as a template:
Thanks! My first time adding a space-script, so cool! Really like SilverBullet so far. I’ve been a Notion user, but somehow this simplified, own my data workflow is appealing to me. Setup a MediaWiki years ago, like the .md file approach.