Skip to content

Instantly share code, notes, and snippets.

@dnordstrom
Created September 7, 2011 18:25
Show Gist options
  • Save dnordstrom/1201314 to your computer and use it in GitHub Desktop.
Save dnordstrom/1201314 to your computer and use it in GitHub Desktop.
Ugly code
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