hubot-logger
hubot-logger copied to clipboard
Not seeing expected results when using What did I miss in the last 18 hours?
Since where this is used is in different timezones and standard policy is to use UTC. When I join I typically query what I missed since I left 12-18 hrs sometimes. However "What did I miss in the last 18 hours?" only returns what occured on the same day as start not end.
<William> Milton: What did I miss in the last 19 hours?
<Milton> Debug: now 2013-12-20T15:29:08+00:00 | start 2013-12-19T20:29:08+00:00
Only returns messages from the 19th
I'm considering adding an additional condition that would check if start and end are different days. If so then query start to start.endofDay then a second query to get logs for end.startofday to end.
Any better insight?
I managed to work around this. Open to better ways to do it but my WIP mess is
robot.respond /what did I miss in the [pl]ast ([0-9]+) (seconds?|minutes?|hours?)\??/i, (msg) ->
num = parseInt(msg.match[1])
if isNaN(num)
msg.reply "I'm not sure how much time #{msg.match[1]} #{msg.match[2]} refers to."
return
now = moment()
ntmp = moment()
start = moment().subtract(msg.match[2][0], num)
stmp = moment().subtract(msg.match[2][0], num)
msg.reply "Debug: now #{now.utc().format()} | start #{start.utc().format()}"
if now.diff(start, 'days', true) > 1
robot.send direct_user(msg.message.user.id, msg.message.user.room),
"I can only tell you activity for the last 24 hours in a message. Please try again."
return
if now.isAfter(start, 'days')
debugmsgs = """
Debug: Edge Case where now is the next day after start
query 1 #{start.utc().format()} | #{stmp.endOf('day').utc().format()}
query 2 #{ntmp.startOf('day').utc().format()} | #{now.utc().format()}
"""
msg.reply debugmsgs
get_logs_for_range client, start, stmp, msg.message.user.room, (logs) ->
logs_formatted = format_logs_for_chat(logs)
robot.send direct_user(msg.message.user.id, msg.message.user.room), logs_formatted.join("\n")
get_logs_for_range client, ntmp, now, msg.message.user.room, (logs) ->
logs_formatted = format_logs_for_chat(logs)
robot.send direct_user(msg.message.user.id, msg.message.user.room), logs_formatted.join("\n")
else
get_logs_for_range client, start, moment(), msg.message.user.room, (logs) ->
logs_formatted = format_logs_for_chat(logs)
robot.send direct_user(msg.message.user.id, msg.message.user.room), logs_formatted.join("\n")
I took out the 24 hour check since I'm not sure that really didn't have an issue either given my use case.