たとえば、今日 (3 月 29 日) はその年の 88 日です。次に、月とその月の日を含むハッシュを返します。
{"month" => "March, "day" => 29}
このコードの何が問題なのかよくわかりませんが、常にnil
. 何かご意見は?Ruby 1.8.7 p358 を使用しています。
def number_to_date(days)
date = case days
when days <= 31 then {"month" => "January", "day" => days}
when days <= 59 then {"month" => "February", "day" => (days - 31)}
when days <= 90 then {"month" => "March", "day" => (days - 59)}
when days <= 120 then {"month" => "April", "day" => (days - 90)}
when days <= 151 then {"month" => "May", "day" => (days - 120)}
when days <= 181 then {"month" => "June", "day" => (days - 151)}
when days <= 212 then {"month" => "July", "day" => (days - 181)}
when days <= 243 then {"month" => "August", "day" => (days - 212)}
when days <= 273 then {"month" => "September", "day" => (days - 243)}
when days <= 304 then {"month" => "October", "day" => (days - 273)}
when days <= 334 then {"month" => "November", "day" => (days - 304)}
when days <= 365 then {"month" => "December", "day" => (days - 334)}
end
return date
end