Skip to content

Instantly share code, notes, and snippets.

@marsz
Created July 31, 2013 07:56
Show Gist options
  • Save marsz/6120163 to your computer and use it in GitHub Desktop.
Save marsz/6120163 to your computer and use it in GitHub Desktop.
星座判斷
def within_date?(date, from_date, to_date)
date = date.to_date
(Time.parse("#{date.year}/#{from_date}").to_date..Time.parse("#{date.year}/#{to_date}").to_date).include?(date)
end
date = Time.parse("1982-3-30")
puts within_date?(date, "3/1", "3/30").inspect
puts within_date?(date, "2/1", "2/28").inspect
if within_date?(date, "3/1", "3/30")
astro = 1
elsif within_date?(date, "3/1", "3/30")
astro = 2
else # 跨年的摩羯座
astro = 10
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment