Skip to content

Commit

Permalink
Use moment.js to emit friendlier output strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mnvr committed Feb 15, 2015
1 parent 8ad32b0 commit 35fe194
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"license": "MIT",
"dependencies": {
"chrono-node": "^1.0.2",
"node-uuid": "^1.4.2"
"node-uuid": "^1.4.2",
"moment": "^2.9.0"
},
"devDependencies": {
"coffee-script": "^1.8.0",
Expand Down
4 changes: 3 additions & 1 deletion scripts/remind-her.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

chrono = require 'chrono-node'
uuid = require 'node-uuid'
moment = require 'moment'

# Method that builds on top of the chrono date parser and tries to
# extract a date and an action from a given string.
Expand Down Expand Up @@ -85,4 +86,5 @@ module.exports = (robot) ->

reminders.queue reminder

msg.send "I'll remind you to #{action} at #{reminder.date.toLocaleString()}"
outputDate = moment(date).calendar()
msg.send "I'll remind you to #{action} at #{outputDate}"
29 changes: 23 additions & 6 deletions test/remind-her.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ process.env.TZ = 'UTC'
Helper = require 'hubot-test-helper'
helper = new Helper('../scripts')

createRoom = () ->
room = helper.createRoom()
room.lastMessage = ->
[..., last] = @messages
last[1]
room

describe 'Reminder Strings', ->
room = null
beforeEach ->
room = helper.createRoom()
room.lastMessage = ->
[..., last] = @messages
last[1]
room = createRoom()

it 'that do not specify a date are ignored', ->
room.user.say 'user', 'hubot remind me at not a date to do task'
assert.match room.lastMessage(), /I did not understand the date/

it 'can be absolute chrono formats specified with "at"', ->
room.user.say 'user', 'hubot remind me at Saturday, 17 August 2513 to do task'
assert.equal "I'll remind you to do task at Thu Aug 17 2513 12:00:00 GMT+0000 (UTC)", room.lastMessage()
room.user.say 'user', 'hubot remind me at tomorrow 5 PM to foo'
assert.match room.lastMessage(), /I'll remind you to foo/

it 'can be relative chrono formats specified with "in"', ->
room.user.say 'user', 'hubot remind me in 15 minutes to foo'
Expand All @@ -28,3 +32,16 @@ describe 'Reminder Strings', ->
it 'subject is optional', ->
room.user.say 'user', 'hubot remind 5 PM to foo'
assert.match room.lastMessage(), /I'll remind you to foo at/

describe 'Output Format', ->
it 'uses moment.js outputs', ->
room = createRoom()
room.user.say 'user', 'hubot remind Saturday, 17 August 2513 to do task'
# http://momentjs.com/docs/#/displaying/calendar-time/
assert.match room.lastMessage(), /08\/17\/2513/

describe 'Input/Output Functional test', ->
it 'relative dates work in both input and output', ->
room = createRoom()
room.user.say 'user', 'hubot remind me at tomorrow 5 PM to do task'
assert.match room.lastMessage(), /I'll remind you to do task at Tomorrow at 5:00 PM/

0 comments on commit 35fe194

Please sign in to comment.