-
-
Save darrarski/71fb88fe172f5f4fd369a4d245e72912 to your computer and use it in GitHub Desktop.
Scriptable time zones widget
This file contains 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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: cyan; icon-glyph: clock; | |
// list of time zones: https://gist.github.com/rxaviers/8481876 | |
let configs = [ | |
{name: "Warsaw", timzeZone: "Europe/Berlin", bgColor: new Color("BF0D3E",1)}, | |
{name: "Recife", timeZone: "America/Recife", bgColor: new Color("009639",1)}, | |
{name: "Los Angeles", timeZone: "America/Los_Angeles", bgColor: new Color("3878d1",1)} | |
] | |
let widget = new ListWidget() | |
widget.backgroundColor = Color.black() | |
let row = widget.addStack() | |
widget.setPadding(5,5,5,5) | |
for (i in configs) { | |
addClock(configs[i], row) | |
if (i < configs.length -1) { | |
row.addSpacer(4) | |
} | |
} | |
function currentDate(timeZone) { | |
return new Date(new Date().toLocaleString("en-US", {timeZone: timeZone})) | |
} | |
function addClock(config, r) { | |
let placeTime = currentDate(config.timeZone) | |
let bgColor = Color.white() | |
if (config.bgColor) { | |
bgColor = config.bgColor | |
} | |
let stack = r.addStack() | |
stack.setPadding(0,0,0,0) | |
stack.spacing = 0 | |
stack.layoutVertically() | |
stack.backgroundColor = bgColor | |
stack.cornerRadius = 20 | |
let titleStack = stack.addStack() | |
titleStack.addSpacer() | |
let title = titleStack.addText(config.name) | |
title.font = Font.regularRoundedSystemFont(14) | |
titleStack.backgroundColor = new Color("ffffff", 0.3) | |
titleStack.addSpacer() | |
stack.addSpacer() | |
let formatterTime = new DateFormatter() | |
formatterTime.dateFormat = "H:mm" | |
let timeStack = stack.addStack() | |
timeStack.addSpacer() | |
let time = timeStack.addText(formatterTime.string(placeTime)) | |
time.font = Font.boldRoundedSystemFont(30) | |
time.textColor = Color.white() | |
timeStack.addSpacer() | |
stack.addSpacer() | |
let formatterDay = new DateFormatter() | |
formatterDay.dateFormat = "eee" | |
let dayStack = stack.addStack() | |
dayStack.addSpacer() | |
let day = dayStack.addText(formatterDay.string(placeTime).toLocaleUpperCase()) | |
day.font = Font.regularRoundedSystemFont(20) | |
day.textColor = Color.white() | |
dayStack.addSpacer() | |
let formatterDate = new DateFormatter() | |
formatterDate.dateFormat = "dd/MM" | |
let dateStack = stack.addStack() | |
dateStack.addSpacer() | |
let date = dateStack.addText(formatterDate.string(placeTime)) | |
date.font = Font.regularRoundedSystemFont(20) | |
date.textColor = Color.white() | |
dateStack.addSpacer() | |
stack.addSpacer() | |
} | |
widget.presentMedium() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment