Sha256: a15be691112854b8150139c8d303aee6b43c1b87eed2f39886c739a26ecd2d28

Contents?: true

Size: 712 Bytes

Versions: 8

Compression:

Stored size: 712 Bytes

Contents

require 'active_support'
require 'active_support/time'

module FeCoreExt::CoreExt
end

module FeCoreExt::CoreExt::Date
  def end_of_month?
    self == end_of_month
  end

  def range(duration)
    Range.new(*[self + duration, self].minmax)
  end

  def to_time_range
    Range.new(beginning_of_day, end_of_day)
  end
end

module FeCoreExt::CoreExt::DateClassMethods
  def parse_as_future(string)
    date = parse(string)
    date > current ? date : date + 1.year
  end

  def parse_heisei(string)
    string.match('平成(\d+)年(\d+)月(\d+)日') {
      Date.new($1.to_i + 1988, $2.to_i, $3.to_i)
    }
  end
end

class Date
  include FeCoreExt::CoreExt::Date
  extend FeCoreExt::CoreExt::DateClassMethods
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fe_core_ext-0.8.3 lib/fe_core_ext/core_ext/date.rb
fe_core_ext-0.8.2 lib/fe_core_ext/core_ext/date.rb
fe_core_ext-0.8.1 lib/fe_core_ext/core_ext/date.rb
fe_core_ext-0.7.0 lib/fe_core_ext/core_ext/date.rb
fe_core_ext-0.6.0 lib/fe_core_ext/core_ext/date.rb
fe_core_ext-0.5.0 lib/fe_core_ext/core_ext/date.rb
fe_core_ext-0.4.0 lib/fe_core_ext/core_ext/date.rb
fe_core_ext-0.3.0 lib/fe_core_ext/core_ext/date.rb