Skip to content

Instantly share code, notes, and snippets.

@eggsy
Last active March 6, 2024 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eggsy/176bab135677d1b2110eef8ce2cdb3c9 to your computer and use it in GitHub Desktop.
Save eggsy/176bab135677d1b2110eef8ce2cdb3c9 to your computer and use it in GitHub Desktop.
Easily watch every country that participated in Ship for World Youth 2024 program time from your home screen!
const widget = await createWidget();
if (config.runsInWidget) {
Script.setWidget(widget);
} else {
widget.presentMedium();
}
Script.complete();
async function createWidget() {
const wg = new ListWidget();
const currentDate = new Date();
const titleText = wg.addText("๐Ÿ• SWY35 Clock");
titleText.centerAlignText();
titleText.font = new Font("Menlo-Bold", 14)
wg.addSpacer(10)
const countries = [
{
name: "Argentina",
timeZone: "America/Argentina/Buenos_Aires",
flag: "๐Ÿ‡ฆ๐Ÿ‡ท",
},
{ name: "Ethiopia", timeZone: "Africa/Addis_Ababa", flag: "๐Ÿ‡ช๐Ÿ‡น" },
{ name: "France", timeZone: "Europe/Paris", flag: "๐Ÿ‡ซ๐Ÿ‡ท" },
{ name: "India", timeZone: "Asia/Kolkata", flag: "๐Ÿ‡ฎ๐Ÿ‡ณ" },
{ name: "Ireland", timeZone: "Europe/Dublin", flag: "๐Ÿ‡ฎ๐Ÿ‡ช" },
{ name: "Japan", timeZone: "Asia/Tokyo", flag: "๐Ÿ‡ฏ๐Ÿ‡ต" },
{ name: "Jordan", timeZone: "Asia/Amman", flag: "๐Ÿ‡ฏ๐Ÿ‡ด" },
{ name: "Kenya", timeZone: "Africa/Nairobi", flag: "๐Ÿ‡ฐ๐Ÿ‡ช" },
{ name: "Mexico", timeZone: "America/Mexico_City", flag: "๐Ÿ‡ฒ๐Ÿ‡ฝ" },
{ name: "New Zealand", timeZone: "Pacific/Auckland", flag: "๐Ÿ‡ณ๐Ÿ‡ฟ" },
{ name: "Solomon", timeZone: "Pacific/Guadalcanal", flag: "๐Ÿ‡ธ๐Ÿ‡ง" },
{ name: "Tรผrkiye", timeZone: "Europe/Istanbul", flag: "๐Ÿ‡น๐Ÿ‡ท" },
{ name: "UAE", timeZone: "Asia/Dubai", flag: "๐Ÿ‡ฆ๐Ÿ‡ช" },
{ name: "Zambia", timeZone: "Africa/Lusaka", flag: "๐Ÿ‡ฟ๐Ÿ‡ฒ" },
];
const halfwayIndex = Math.ceil(countries.length / 2);
const parentStack = wg.addStack();
const leftStack = parentStack.addStack();
parentStack.addSpacer(12);
const rightStack = parentStack.addStack();
leftStack.layoutVertically();
rightStack.layoutVertically();
leftStack.spacing = 2;
rightStack.spacing = 2;
for (const countryIndex in countries) {
const country = countries[countryIndex];
const countryDate = new Date(
new Date().toLocaleString("en-US", { timeZone: country.timeZone })
);
const time = new Date().toLocaleTimeString("en-US", {
hour: "2-digit",
minute: "2-digit",
timeZone: country.timeZone,
});
const timeText = `${country.flag} ${country.name}: ${time}`;
if (currentDate.getDate() !== countryDate.getDate()) {
const dayDifference = currentDate.getDate() - countryDate.getDate();
const dayNotice =
dayDifference > 0
? `(+${dayDifference})`
: `(-${Math.abs(dayDifference)})`;
timeText.text += ` ${dayNotice}`;
}
if (countryIndex < halfwayIndex) {
const t = leftStack.addText(timeText);
t.font = new Font("Menlo", 11);
} else {
const t = rightStack.addText(timeText);
t.font = new Font("Menlo", 11);
}
}
return wg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment