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



24
25
26
27
28
# File 'lib/iso8601/months.rb', line 24

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)


37
38
39
40
41
42
# File 'lib/iso8601/months.rb', line 37

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)


59
60
61
# File 'lib/iso8601/months.rb', line 59

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)


51
52
53
# File 'lib/iso8601/months.rb', line 51

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