Skip to content

Instantly share code, notes, and snippets.

@probablycorey
Created September 23, 2016 23:07
Show Gist options
  • Save probablycorey/d215313bc9f9804e7a731c4ab58d776e to your computer and use it in GitHub Desktop.
Save probablycorey/d215313bc9f9804e7a731c4ab58d776e to your computer and use it in GitHub Desktop.
Better date parsing
def parse_date_range(options)
from = Time.zone.parse(options[:from]) rescue ArgumentError
to = Time.zone.parse(options[:to]) rescue ArgumentError
to ||= from.try?(:next_day) || Date.current
from ||= to.begining_of_month
time_range = from..to
days_in_range = (to - from).to_i
to = from + MAX_DAY_RANGE.days if days_in_range > MAX_DAY_RANGE
from..to
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment