Created
September 23, 2016 23:07
-
-
Save probablycorey/d215313bc9f9804e7a731c4ab58d776e to your computer and use it in GitHub Desktop.
Better date parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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