From 77db37d631f89e9a10ddff6aa7f6ec3ad3c6494c Mon Sep 17 00:00:00 2001 From: Lajos Koszti Date: Thu, 10 Dec 2015 14:40:34 +0100 Subject: [PATCH 1/2] Format utc time output --- scripts/standup.coffee | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/scripts/standup.coffee b/scripts/standup.coffee index 236986f..8db3a68 100644 --- a/scripts/standup.coffee +++ b/scripts/standup.coffee @@ -15,6 +15,7 @@ # hubot list standups - See all standups for this room # hubot list standups in every room - See all standups in every room # hubot delete hh:mm standup - If you have a standup at hh:mm, deletes it +# hubot delete hh:mm UTC+2 standup - If you have a standup at hh:mm UTC+2, deletes it # hubot delete all standups - Deletes all standups for this room. # # Dependencies: @@ -26,10 +27,16 @@ cronJob = require('cron').CronJob _ = require('underscore') +formatUTCTime = (standup) -> + if standup.utc + standup.time + ' UTC' + standup.utc + else + standup.time + module.exports = (robot) -> + # Compares current time to the time of the standup # to see if it should be fired. - standupShouldFire = (standup) -> standupTime = standup.time utc = standup.utc @@ -110,11 +117,12 @@ module.exports = (robot) -> updateBrain standupsToKeep standups.length - (standupsToKeep.length) - clearSpecificStandupForRoom = (room, time) -> + clearSpecificStandupForRoom = (room, time, utc) -> standups = getStandups() standupsToKeep = _.reject(standups, room: room - time: time) + time: time + utc: utc) updateBrain standupsToKeep standups.length - (standupsToKeep.length) @@ -145,21 +153,26 @@ module.exports = (robot) -> standupsCleared = clearAllStandupsForRoom(findRoom(msg)) msg.send 'Deleted ' + standupsCleared + ' standup' + (if standupsCleared == 1 then '' else 's') + '. No more standups for you.' return - robot.respond /delete ([0-5]?[0-9]:[0-5]?[0-9]) standup/i, (msg) -> + + robot.respond /delete ([0-5]?[0-9]:[0-5]?[0-9])(?: UTC([+-](?:[0-9]|1[0-3])))? standup/i, (msg) -> time = msg.match[1] - standupsCleared = clearSpecificStandupForRoom(findRoom(msg), time) + utc = msg.match[2] + standupsCleared = clearSpecificStandupForRoom(findRoom(msg), time, utc) + if standupsCleared == 0 - msg.send 'Nice try. You don\'t even have a standup at ' + time + msg.send 'Nice try. You don\'t even have a standup at ' + formatUTCTime({time: time, utc: utc}) else - msg.send 'Deleted your ' + time + ' standup.' + msg.send 'Deleted your ' + formatUTCTime({time: time, utc: utc}) + ' standup.' return + robot.respond /create standup ((?:[01]?[0-9]|2[0-4]):[0-5]?[0-9])$/i, (msg) -> time = msg.match[1] room = findRoom(msg) saveStandup room, time msg.send 'Ok, from now on I\'ll remind this room to do a standup every weekday at ' + time return - robot.respond /create standup ((?:[01]?[0-9]|2[0-4]):[0-5]?[0-9]) UTC([+-]([0-9]|1[0-3]))$/i, (msg) -> + + robot.respond /create standup ((?:[01]?[0-9]|2[0-4]):[0-5]?[0-9]) UTC([+-](?:[0-9]|1[0-3]))$/i, (msg) -> time = msg.match[1] utc = msg.match[2] room = findRoom(msg) @@ -171,12 +184,7 @@ module.exports = (robot) -> if standups.length == 0 msg.send 'Well this is awkward. You haven\'t got any standups set :-/' else - standupsText = [ 'Here\'s your standups:' ].concat(_.map(standups, (standup) -> - if standup.utc - standup.time + ' UTC' + standup.utc - else - standup.time - )) + standupsText = [ 'Here\'s your standups:' ].concat(_.map(standups, formatUTCTime)) msg.send standupsText.join('\n') return robot.respond /list standups in every room/i, (msg) -> @@ -185,7 +193,7 @@ module.exports = (robot) -> msg.send 'No, because there aren\'t any.' else standupsText = [ 'Here\'s the standups for every room:' ].concat(_.map(standups, (standup) -> - 'Room: ' + standup.room + ', Time: ' + standup.time + 'Room: ' + standup.room + ', Time: ' + formatUTCTime(standup) )) msg.send standupsText.join('\n') return From 723947f340d22c4ef9b166e98c365924b85decf4 Mon Sep 17 00:00:00 2001 From: Lajos Koszti Date: Thu, 10 Dec 2015 14:42:37 +0100 Subject: [PATCH 2/2] Add lines between robot.respond calls Makes the code more readable --- scripts/standup.coffee | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/standup.coffee b/scripts/standup.coffee index 8db3a68..732b67e 100644 --- a/scripts/standup.coffee +++ b/scripts/standup.coffee @@ -43,23 +43,31 @@ module.exports = (robot) -> now = new Date currentHours = undefined currentMinutes = undefined + if utc currentHours = now.getUTCHours() + parseInt(utc, 10) currentMinutes = now.getUTCMinutes() + if currentHours > 23 currentHours -= 23 + else currentHours = now.getHours() currentMinutes = now.getMinutes() + standupHours = standupTime.split(':')[0] standupMinutes = standupTime.split(':')[1] + try standupHours = parseInt(standupHours, 10) standupMinutes = parseInt(standupMinutes, 10) + catch _error return false + if standupHours == currentHours and standupMinutes == currentMinutes return true + false # Returns all standups. @@ -97,10 +105,11 @@ module.exports = (robot) -> saveStandup = (room, time, utc) -> standups = getStandups() - newStandup = + newStandup = time: time room: room utc: utc + standups.push newStandup updateBrain standups return @@ -179,6 +188,7 @@ module.exports = (robot) -> saveStandup room, time, utc msg.send 'Ok, from now on I\'ll remind this room to do a standup every weekday at ' + time + ' UTC' + utc return + robot.respond /list standups$/i, (msg) -> standups = getStandupsForRoom(findRoom(msg)) if standups.length == 0 @@ -187,6 +197,7 @@ module.exports = (robot) -> standupsText = [ 'Here\'s your standups:' ].concat(_.map(standups, formatUTCTime)) msg.send standupsText.join('\n') return + robot.respond /list standups in every room/i, (msg) -> standups = getStandups() if standups.length == 0 @@ -197,6 +208,7 @@ module.exports = (robot) -> )) msg.send standupsText.join('\n') return + robot.respond /standup help/i, (msg) -> message = [] message.push 'I can remind you to do your daily standup!'