Guest User

Untitled

a guest
Feb 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. require 'rubygems'
  2. require_gem 'activesupport'
  3. require 'active_support'
  4. require 'date'
  5.  
  6. class String
  7. def time_string_parse
  8. time_string = downcase.strip.gsub(/\s+/, ' ')
  9. time = Time.now
  10.  
  11. case time_string
  12. when /\btomorrow\b/
  13. time += 86400
  14. end
  15.  
  16. case time_string
  17. when /\bat (\d+)(am|pm)\b/
  18. time = Time.local(time.year, time.month, time.day, $1.to_i + ($2 == 'pm' ? 12 : 0), 0, 0)
  19. end
  20.  
  21. time
  22. end
  23. end
Add Comment
Please, Sign In to add comment