Created
July 31, 2013 07:56
-
-
Save marsz/6120163 to your computer and use it in GitHub Desktop.
星座判斷
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 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