Last active
April 18, 2021 09:43
-
-
Save marco79cgn/f997d530ce548ab9bd77336a09083a93 to your computer and use it in GitHub Desktop.
A Scriptable calendar widget that shows the current covid standard time
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 characters
let widget = new ListWidget() | |
widget.setPadding(14,10,10,10) | |
widget.url = "https://covidstandardtime.com" | |
await loadCovidTime() | |
Script.setWidget(widget) | |
Script.complete() | |
// show a preview of the widget when run in the app, useful for testing | |
if(config.runsInApp) { | |
widget.presentSmall() | |
} | |
async function loadCovidTime() { | |
var param = args.widgetParameter | |
let dayone | |
// day one date can be configured as widget parameter, e.g. "2020-01-01" | |
if(param != null && param.length > 0) { | |
dayone = new Date(param) | |
} else { | |
dayone = new Date("2020-03-01"); | |
} | |
var today = new Date(); | |
var day_delta = Math.floor( (today.getTime() - dayone.getTime()) / (1000 * 3600 * 24) ); | |
let day = ordinal_suffix_of(day_delta) | |
let dateText = widget.addText(getMonthName(dayone).toUpperCase()) | |
dateText.font = Font.boldSystemFont(12) | |
let dayNameText = widget.addText(getWeekday(today)) | |
dayNameText.textColor = Color.red() | |
dayNameText.font = Font.boldSystemFont(20) | |
let dayText = widget.addText(day) | |
dayText.font = Font.semiboldSystemFont(40) | |
let yearText = widget.addText(dayone.getFullYear().toString()) | |
yearText.textOpacity = 0.5 | |
yearText.font = Font.boldSystemFont(20) | |
widget.addSpacer(8) | |
let timeText = widget.addText("Covid Standard Time") | |
timeText.textColor = Color.black() | |
timeText.font = Font.boldSystemFont(10) | |
widget.addSpacer() | |
} | |
function ordinal_suffix_of(n) { | |
var s = ["th", "st", "nd", "rd"], | |
v = n % 100; | |
return n + (s[(v - 20) % 10] || s[v] || s[0]); | |
} | |
function getWeekday(date) { | |
var weekday = new Array(7); | |
weekday[0] = "Sunday"; | |
weekday[1] = "Monday"; | |
weekday[2] = "Tuesday"; | |
weekday[3] = "Wednesday"; | |
weekday[4] = "Thursday"; | |
weekday[5] = "Friday"; | |
weekday[6] = "Saturday"; | |
return weekday[date.getDay()]; | |
} | |
function getMonthName(date) { | |
var monthName = new Array(12); | |
monthName[0] = "January"; | |
monthName[1] = "February"; | |
monthName[2] = "March"; | |
monthName[3] = "April"; | |
monthName[4] = "May"; | |
monthName[5] = "June"; | |
monthName[6] = "July"; | |
monthName[7] = "August"; | |
monthName[8] = "September"; | |
monthName[9] = "October"; | |
monthName[10] = "November"; | |
monthName[11] = "December"; | |
return monthName[date.getMonth()]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Intro
iOS 14 Custom Widget made with the help of the Scriptable app. It shows a calendar of today's date in Covid Standard Time.
Requirements
HowTo: create a new script in the scriptable app, copy/paste the script above and save. Configure the widget afterwards. It's possible to change "day one" by configuring the widget parameter, e.g. "2019-11-17".
Thanks
A big Thank you to @simonbs for making great apps like Scriptable, DataJar or Jayson.