Sha256: 0fd6db9e5d87bfd27ea0fb7499888544504faea62d42bb17497aaff904db192c

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

require 'date'

module FatPeriod
  # An extension of Date for methods useful with respect to FatPeriod::Periods.
  module Date
    # Return the Period of the given chunk size that contains this Date. Chunk
    # can be one of :year, :half, :quarter, :bimonth, :month, :semimonth,
    # :biweek, :week, or :day.
    #
    # @example
    #   date = Date.parse('2015-06-13')
    #   date.expand_to_period(:week)      #=> Period(2015-06-08..2015-06-14)
    #   date.expand_to_period(:semimonth) #=> Period(2015-06-01..2015-06-15)
    #   date.expand_to_period(:quarter)   #=> Period(2015-04-01..2015-06-30)
    #
    # @param chunk [Symbol] one of :year, :half, :quarter, :bimonth, :month,
    #    :semimonth, :biweek, :week, or :day
    # @return [Period] Period of size `chunk` containing self
    def expand_to_period(chunk)
      require 'fat_period'
      Period.new(beginning_of_chunk(chunk), end_of_chunk(chunk))
    end
  end
end

# An extension Date for methods useful with respect to FatPeriod::Periods.
class Date
  include FatPeriod::Date
  # @!parse include FatPeriod::Date
  # @!parse extend FatPeriod::Date::ClassMethods
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fat_period-1.3.1 lib/fat_period/date.rb
fat_period-1.3.0 lib/fat_period/date.rb
fat_period-1.2.1 lib/fat_period/date.rb
fat_period-1.2.0 lib/fat_period/date.rb
fat_period-1.1.1 lib/fat_period/date.rb
fat_period-1.1.0 lib/fat_period/date.rb
fat_period-1.0.3 lib/fat_period/date.rb
fat_period-1.0.2 lib/fat_period/date.rb
fat_period-1.0.0 lib/fat_period/date.rb