Class: ISO8601::Months

Inherits:
Object
  • Object
show all
Includes:
Atomic
Defined in:
lib/iso8601/months.rb

Overview

A Months atom in a Duration

A “calendar month” is the time interval resulting from the division of a “calendar year” in 12 time intervals.

A “duration month” is the duration of 28, 29, 30 or 31 “calendar days” depending on the start and/or the end of the corresponding time interval within the specific “calendar month”.

Constant Summary collapse

AVERAGE_FACTOR =

The “duration month” average is calculated through time intervals of 400 “duration years”. Each cycle of 400 “duration years” has 303 “common years” of 365 “calendar days” and 97 “leap years” of 366 “calendar days”.

Years::AVERAGE_FACTOR / 12

Instance Attribute Summary

Attributes included from Atomic

#atom

Instance Method Summary collapse

Methods included from Atomic

#<=>, #eql?, #hash, #to_f, #to_i, #to_s, #valid_atom?, #valid_base?, #value

Constructor Details

#initialize(atom) ⇒ Months

Returns a new instance of Months.

Parameters:

  • atom (Numeric)

    The atom value



22
23
24
25
26
# File 'lib/iso8601/months.rb', line 22

def initialize(atom)
  valid_atom?(atom)

  @atom = atom
end

Instance Method Details

#factor(base = nil) ⇒ Numeric

The Month factor

Parameters:

  • base (ISO8601::DateTime, nil) (defaults to: nil)

    (nil) The base datetime to compute the month length.

Returns:

  • (Numeric)


35
36
37
38
39
40
# File 'lib/iso8601/months.rb', line 35

def factor(base = nil)
  return AVERAGE_FACTOR if base.nil?
  return calculation(1, base) if atom.zero?

  calculation(atom, base)
end

#symbolSymbol

The atom symbol.

Returns:

  • (Symbol)


57
58
59
# File 'lib/iso8601/months.rb', line 57

def symbol
  :M
end

#to_seconds(base = nil) ⇒ Numeric

The amount of seconds

Parameters:

  • base (ISO8601::DateTime, nil) (defaults to: nil)

    (nil) The base datetime to compute the month length.

Returns:

  • (Numeric)


49
50
51
# File 'lib/iso8601/months.rb', line 49

def to_seconds(base = nil)
  factor(base) * atom
end