Class: ISO8601::Years

Inherits:
Atom
  • Object
show all
Defined in:
lib/iso8601/atoms.rb

Overview

A Years atom in a Duration

A “calendar year” is the cyclic time interval in a calendar which is required for one revolution of the Earth around the Sun and approximated to an integral number of “calendar days”.

A “duration year” is the duration of 365 or 366 “calendar days” depending on the start and/or the end of the corresponding time interval within the specific “calendar year”.

Instance Attribute Summary

Attributes inherited from Atom

#atom, #base

Instance Method Summary collapse

Methods inherited from Atom

#<=>, #eql?, #hash, #initialize, #to_f, #to_i, #to_s, #to_seconds, #value

Constructor Details

This class inherits a constructor from ISO8601::Atom

Instance Method Details

#adjusted_timeObject


126
127
128
# File 'lib/iso8601/atoms.rb', line 126

def adjusted_time
  ::Time.utc((base.year + atom).to_i) - ::Time.utc(base.year)
end

#default_factorObject


130
131
132
# File 'lib/iso8601/atoms.rb', line 130

def default_factor
  ((365 * 303 + 366 * 97) / 400) * 86400
end

#factorInteger

The Year factor

The “duration year” 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”.

Returns:

  • (Integer)

119
120
121
122
123
124
# File 'lib/iso8601/atoms.rb', line 119

def factor
  return default_factor if base.nil?
  return adjusted_time if atom.zero?

  adjusted_time / atom
end

#symbolSymbol

The atom symbol.

Returns:

  • (Symbol)

138
139
140
# File 'lib/iso8601/atoms.rb', line 138

def symbol
  :Y
end