Add extra handling for year format

This commit is contained in:
Omar Roth 2018-08-05 18:35:52 -05:00
parent 9d6cdc3032
commit 5a6b36ecce
2 changed files with 14 additions and 5 deletions

View file

@ -63,7 +63,12 @@ def decode_time(string)
end
def decode_date(string : String)
# Time matches format "20 hours ago", "40 minutes ago"...
# String matches 'YYYY'
if string.match(/\d{4}/)
return Time.new(string.to_i, 1, 1)
end
# String matches format "20 hours ago", "40 minutes ago"...
date = string.split(" ")[-3, 3]
delta = date[0].to_i