Created
September 7, 2011 18:25
-
-
Save dnordstrom/1201314 to your computer and use it in GitHub Desktop.
Ugly code
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 in_range?(day) | |
return true if start_date.nil? || end_date.nil? | |
# Overlaps onto new year, e.g. winter season | |
if start_date.month > end_date.month | |
if day.to_date.month >= start_date.month && day.to_date.month <= 12 # Checking date still in current year | |
if day.to_date.month >= start_date.month | |
if day.to_date.month == start_date.month | |
return true if day.to_date.day >= start_date.day | |
return false | |
end | |
return true | |
end | |
else # Checking date of a new year | |
if day.to_date.month <= end_date.month | |
if day.to_date.month == end_date.month | |
return true if day.to_date.day <= end_date.day | |
return false | |
end | |
return true | |
end | |
end | |
else # Does not overlap to new year, e.g. summer season | |
if day.to_date.month >= start_date.month && day.to_date.month <= end_date.month | |
if day.to_date.month == start_date.month | |
return true if day.to_date.day >= start_date.day | |
return false | |
elsif day.to_date.month == end_date.month | |
return true if day.to_date.day <= end_date.day | |
return false | |
end | |
return true | |
end | |
end | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment