Skip to content

Instantly share code, notes, and snippets.

@benwtr
Created November 3, 2016 03:02
Show Gist options
  • Save benwtr/9492600140fbc8ea56fdeda4daccfd5c to your computer and use it in GitHub Desktop.
Save benwtr/9492600140fbc8ea56fdeda4daccfd5c to your computer and use it in GitHub Desktop.
# Description:
# Hubot interface for timezone.io
#
# Configuration:
# HUBOT_TIMEZONEIO_URL - full team url eg: https://timezone.io/team/buffer
#
# Commands:
# hubot tz - Show team's local time across time zones via timezone.io
#
# Dependencies:
# moment-timezone
#
# Author:
# @benwtr
#
moment = require 'moment-timezone'
timezoneio_url = process.env.HUBOT_TIMEZONEIO_URL || 'https://timezone.io/team/buffer'
data_regex = /appData = (.*);/g
module.exports = (robot) ->
robot.respond /tz/i, (res) ->
robot.http(timezoneio_url)
.get() (err, result, body) ->
if m = data_regex.exec body
d = m[1]
d = JSON.parse d
reply = ''
cur_time = new Date().getTime()
for z in d.timezones
tz = z.tz
time = moment(cur_time).tz(tz).format("ddd h:mmA|zZZ")
names = for person in z.people
person.name
names = names.join(', ')
reply += "#{tz}|#{time} - #{names}\n"
res.reply reply
@benwtr
Copy link
Author

benwtr commented Nov 3, 2016

Example output

America/Los_Angeles|Wed 7:48PM|PDT-0700 - Amy, Andy, Brian, Caryn, Christina, Daniel, Daniel Siemaszkiewicz, Emily, Hamish, Karinna, Katie, Michael, Mike Eckstein, Nicole, Spencer Lanoue, Suni
l, Tyler                                                                                                                                                                                                 
America/Denver|Wed 8:48PM|MDT-0600 - Darcy, Matt Allen, kevan
America/Chicago|Wed 9:48PM|CDT-0500 - Bonnie, Carolyn, Courtney Seiter, Harrison Harnisch, Jordan Morgan, Phil
America/New_York|Wed 10:48PM|EDT-0400 - Adam Farmer, Alex, Arielle Tannenbaum, Dan Farrelly, David, Hailley, Jenny, Joel, Julia, Julian, Kelly, Leo, Patrik, Pioul, Ross, Roy, Super, Tigran, Todd Balsley
, Tom                                                                                                                                                                                                    
America/Asuncion|Wed 11:48PM|PYST-0300 - Humber
Europe/London|Thu 2:48AM|GMT+0000 - Ash Read, Colin, Danny Mulcahy, Dave C, Dave O, Hannah, James, Joe, Juliet, Melissa Alvarez, Mick, Steve Dixon, Tom Dunn
Europe/Paris|Thu 3:48AM|CET+0100 - Boris, David Gasquez, Deborah Rippol, Federico, Ivana, José, Lorenz, Marcus, Max , Mike, Rodolphe Dutel, Åsa
Africa/Johannesburg|Thu 4:48AM|SAST+0200 - Niel de la Rouviere
Asia/Colombo|Thu 8:18AM|+0530+0530 - Adnan
Asia/Singapore|Thu 10:48AM|SGT+0800 - Alfred, Eric, Octa, Stephanie, Steven
Australia/Brisbane|Thu 12:48PM|AEST+1000 - Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment