Class: ActivePeriod::Day

Inherits:
StandardPeriod show all
Includes:
BelongsTo::Month, BelongsTo::Quarter, BelongsTo::Week, BelongsTo::Year
Defined in:
lib/active_period/day.rb

Direct Known Subclasses

Holiday

Instance Method Summary collapse

Methods included from BelongsTo::Year

#year

Methods included from BelongsTo::Quarter

#quarter

Methods included from BelongsTo::Month

#month

Methods included from BelongsTo::Week

#week

Methods inherited from StandardPeriod

#+, #-, #_period, _period, #i18n_scope, #initialize, #next, #prev, #to_i

Methods inherited from Period

#&, #+, #-, #==, #===, #beginless?, #boundless?, #calculated_begin, #calculated_end, #endless?, #infinite?, #initialize, #next, #prev, #to_i, #|

Methods included from HasMany::Holidays

#holidays

Methods included from Comparable

#<=>, #include?

Methods inherited from Range

#to_period

Constructor Details

This class inherits a constructor from ActivePeriod::StandardPeriod

Instance Method Details

#holiday?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/active_period/day.rb', line 33

def holiday?(...)
  raise I18n.t(:gem_require, scope: %i[active_period holiday_period]) unless Object.const_defined?('Holidays')
  holidays(...).first.present?
end

#i18n(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/active_period/day.rb', line 22

def i18n(&block)
  return yield(from, to) if block.present?

  I18n.t(:default_format,
         scope:   i18n_scope,
         wday:    I18n.l(from, format: '%A').capitalize,
         day:     from.day,
         month:   I18n.l(from, format: '%B').capitalize,
         year:    from.year)
end

#strftime(format) ⇒ Object



14
15
16
# File 'lib/active_period/day.rb', line 14

def strftime(format)
  from.strftime(format)
end

#to_s(format: '%d/%m/%Y') ⇒ Object



18
19
20
# File 'lib/active_period/day.rb', line 18

def to_s(format: '%d/%m/%Y')
  strftime(format)
end