Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

ActiveSupport | Date calculations

概要

Date calculations

詳細

Date calculations について

Date calculations

日付の操作に関する各種メソッドを提供します。

サンプル

# encoding: utf-8
require 'active_support/core_ext/date/calculations'
require 'tbpgr_utils'

date = Date.new(2014,1,1)
bulk_puts_eval binding, <<-EOS
Date.current
Date.tomorrow
Date.yesterday
Date.beginning_of_week
date.prev_year
date.next_year
date.prev_month
date.next_month
date.prev_quarter
date.next_quarter
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

Date.current # => #<Date: 2014-03-28 ((2456745j,0s,0n),+0s,2299161j)>
Date.tomorrow # => #<Date: 2014-03-29 ((2456746j,0s,0n),+0s,2299161j)>
Date.yesterday # => #<Date: 2014-03-27 ((2456744j,0s,0n),+0s,2299161j)>
Date.beginning_of_week # => :monday
date.prev_year # => #<Date: 2013-01-01 ((2456294j,0s,0n),+0s,2299161j)>
date.next_year # => #<Date: 2015-01-01 ((2457024j,0s,0n),+0s,2299161j)>
date.prev_month # => #<Date: 2013-12-01 ((2456628j,0s,0n),+0s,2299161j)>
date.next_month # => #<Date: 2014-02-01 ((2456690j,0s,0n),+0s,2299161j)>
date.prev_quarter # => #<Date: 2013-10-01 ((2456567j,0s,0n),+0s,2299161j)>
date.next_quarter # => #<Date: 2014-04-01 ((2456749j,0s,0n),+0s,2299161j)>