Last active
February 14, 2025 23:21
-
-
Save dcatanzaro/4541f2a06e42110908fef25c2a2ee30c to your computer and use it in GitHub Desktop.
Revisions
-
dcatanzaro revised this gist
Dec 28, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -95,7 +95,7 @@ async function createWidget() { widget.addSpacer(10); const day = widget.addText( `${nextHoliday.dia} de ${months[nextHoliday.mes - 1]} de ${yearNext}` ); day.textColor = Color.black(); day.textOpacity = 1; -
dcatanzaro revised this gist
Dec 28, 2020 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ async function getNextHoliday() { ); if (!holiday) { holiday = resHolidays[0]; } return holiday; @@ -63,12 +63,17 @@ async function createWidget() { ]; const year = now.getFullYear(); let yearNext = year; const nextHoliday = await getNextHoliday(); if (nextHoliday.id == "año-nuevo") { yearNext++; } const diff = diffDays( `${now.getMonth() + 1}/${now.getDate()}/${year}`, `${nextHoliday.mes}/${nextHoliday.dia}/${yearNext}` ); const widget = new ListWidget(); -
dcatanzaro created this gist
Oct 4, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,112 @@ //Twitter: @DamianCatanzaro const widget = await createWidget(); if (config.runsInWidget) { Script.setWidget(widget); Script.complete(); } else { widget.presentLarge(); } async function getNextHoliday() { const now = new Date(); const year = now.getFullYear(); const url = `https://nolaborables.com.ar/api/v2/feriados/${year}`; const reqHolidays = new Request(url); const resHolidays = await reqHolidays.loadJSON(); const today = { day: now.getDate(), month: now.getMonth() + 1, }; let holiday = resHolidays.find( (h) => (h.mes === today.month && h.dia > today.day) || h.mes > today.month ); if (!holiday) { holiday = holidays[0]; } return holiday; } function diffDays(date_1, date_2) { const date1 = new Date(date_1); const date2 = new Date(date_2); const diffTime = Math.abs(date2 - date1); const diff = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); return diff; } async function createWidget() { const now = new Date(); const months = [ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre", ]; const year = now.getFullYear(); const nextHoliday = await getNextHoliday(); const diff = diffDays( `${now.getMonth() + 1}/${now.getDate()}/${year}`, `${nextHoliday.mes}/${nextHoliday.dia}/${year}` ); const widget = new ListWidget(); widget.addSpacer(40); const title = widget.addText("Faltan"); title.textColor = new Color("#555"); title.textOpacity = 1; title.centerAlignText(); title.font = new Font("PingFangTC-Medium", 18); const time = widget.addText(`${diff} días`); time.textColor = new Color("#2e7d33"); time.textOpacity = 1; time.centerAlignText(); time.font = new Font("PingFangTC-Medium", 24); widget.addSpacer(10); const day = widget.addText( `${nextHoliday.dia} de ${months[nextHoliday.mes - 1]} de ${year}` ); day.textColor = Color.black(); day.textOpacity = 1; day.leftAlignText(); day.font = new Font("PingFangTC-Medium", 10); const text = widget.addText(nextHoliday.motivo); text.textColor = new Color("#2e7d33"); text.textOpacity = 1; text.leftAlignText(); text.font = new Font("PingFangTC-Medium", 10); const imgReq = await new Request("https://i.imgur.com/RWYIJAs.png"); const img = await imgReq.loadImage(); widget.backgroundImage = img; return widget; }