business_time gem
business_time gemが便利そう。
このgemを使うと、Dateに対していろいろなmethodが使えるようになる。
[4] pry(#<Date>):1> Date.new(2015,1,2).workday?
=> true
[5] pry(#<Date>):1> Date.today.workday?
=> true
[6] pry(#<Date>):1> Date.today.weekday?
=> true
[7] pry(#<Date>):1> Date.today.monday?
=> true
# 特定の日付までの営業日を計算
[8] pry(#<Date>):1> Date.today.business_days_until(1.month.since)
=> 21
-
創立記念日
などの、会社独自の祝日もカスタマイズ可能
BusinessTime::Config.holidays << Date.parse('会社独自の休みなど')
- config fileも作れる
rails generate business_time:config
- configに日本の祝日リストを持っておけば、判断methodを別途作成しなくても、Dateに生えるのが便利
business_time:
beginning_of_workday: 9:00 am
end_of_workday: 5:00 pm
holidays:
- January 01, 2014
- January 13, 2014
- February 11, 2014
- March 21, 2014
- April 29, 2014
- May 03, 2014
- May 05, 2014
- May 06, 2014
- July 21, 2014
- September 15, 2014
- September 23, 2014
- October 13, 2014
- November 03, 2014
- November 24, 2014
- December 23, 2014
- January 01, 2015
- January 12, 2015
- February 11, 2015
- March 21, 2015
- April 29, 2015
- May 03, 2015
- May 04, 2015
- May 05, 2015
- May 06, 2015
- July 20, 2015
- September 21, 2015
- September 23, 2015
- October 12, 2015
- November 03, 2015
- November 23, 2015
- December 23, 2015
- January 01, 2016
- January 11, 2016
- February 11, 2016
- March 21, 2016
- April 29, 2016
- May 03, 2016
- May 04, 2016
- May 05, 2016
- July 18, 2016
- August 11, 2016
- September 19, 2016
- September 22, 2016
- October 10, 2016
- November 03, 2016
- November 23, 2016
- December 23, 2016
work_week:
- mon
- tue
- wed
- thu
- fri
[12] pry(#<Date>):1> Date.new(2015,1,1).workday?
=> false
[13] pry(#<Date>):1> Date.new(2016,12,23).workday?
=> false
- holiday_jp と組み合わせても面白いかも
komagata/holiday_jp