'2012-10-01', :end_d-6ren">
gpt4 book ai didi

ruby - 获取季度的开始/结束日期

转载 作者:数据小太阳 更新时间:2023-10-29 07:43:22 27 4
gpt4 key购买 nike

我如何计算日期的 quarter begin/end dates ?例如,如果我给出方法 "2012-10-11" 我想返回:{ :begin_date => '2012-10-01', :end_date => '2012-12 -31'

def quarter_dates(date = Date.today)
# TODO...
return {
:begin_date => begin_date,
:end_date => end_date
}
end

最佳答案

ActiveSupport提供 beginning_of_quarterend_of_quarter仅此而已:

require 'active_support/core_ext/date/calculations'

def quarter_dates(date = Date.today)
{
begin_date: date.beginning_of_quarter,
end_date: date.end_of_quarter
}
end

关于ruby - 获取季度的开始/结束日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13001341/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com