Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get country timezones with the current datetime
- *
- * @return {array} datetime, timezone, country, flag, continents
- * @customfunction
- */
- function COUNTRYTIMEZONES(){
- const url = "https://restcountries.com/v3.1/all"
- const resp = UrlFetchApp.fetch(url)
- const headers = ["DateTime", "Timezone", "Country", "Flag", "Continents"]
- const results = [];
- const now = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "yyyy-MM-dd HH:MM:ss")
- JSON.parse(resp.getContentText())
- .forEach(c => {
- const name = c.name.official
- const flag = c.flag
- const continents = c.continents.join(", ")
- c.timezones.forEach(tz => {
- const date = new Date(now + " " + tz)
- results.push([date, tz, name, flag, continents])
- })
- })
- const sorted = results.sort((a, b) => {
- if (a[1] < b[1]) return -1
- if (a[1] > b[1]) return 1
- return 0
- })
- sorted.unshift(headers)
- return sorted
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement