用Ruby计算一年中的周数 [英] Calculating the number of weeks in a year with Ruby
本文介绍了用Ruby计算一年中的周数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
def num_weeks(year = Date.today.year)
Date.new(年,12,28).cweek#magick date!
end
long_iso_years =(2000..2400).select {| year | num_weeks(year)== 53}
产生与维基百科
Is there a way in Ruby to calculate the number of weeks(ISO 8601) for a given year? I'm currently using a lookup table and I'd like to stop using it.
解决方案
def num_weeks(year = Date.today.year)
Date.new(year, 12, 28).cweek # magick date!
end
long_iso_years = (2000..2400).select{|year| num_weeks(year) == 53}
Yields the same list as wikipedia
这篇关于用Ruby计算一年中的周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文