123456789_123456789_123456789_123456789_123456789_

Class: TZInfo::AnnualRules Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/tzinfo/annual_rules.rb

Overview

A set of rules that define when transitions occur in time zones with annually occurring daylight savings time.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#dst_end_ruleTransitionRule (readonly)

Returns:

  • (TransitionRule)

    the rule that determines when daylight savings time ends.

[ GitHub ]

  
# File 'lib/tzinfo/annual_rules.rb', line 24

attr_reader :dst_end_rule

#dst_offsetTimezoneOffset (readonly)

Returns:

  • (TimezoneOffset)

    the offset that applies when daylight savings time is in force.

[ GitHub ]

  
# File 'lib/tzinfo/annual_rules.rb', line 16

attr_reader :dst_offset

#dst_start_ruleTransitionRule (readonly)

Returns:

  • (TransitionRule)

    the rule that determines when daylight savings time starts.

[ GitHub ]

  
# File 'lib/tzinfo/annual_rules.rb', line 20

attr_reader :dst_start_rule

#std_offsetTimezoneOffset (readonly)

Returns:

  • (TimezoneOffset)

    the standard offset that applies when daylight savings time is not in force.

[ GitHub ]

  
# File 'lib/tzinfo/annual_rules.rb', line 12

attr_reader :std_offset

Instance Method Details

#apply_rule(rule, from_offset, to_offset, year) ⇒ TimezoneTransition (private)

Applies a given rule between offsets on a year.

Parameters:

  • rule (TransitionRule)

    the rule to apply.

  • from_offset (TimezoneOffset)

    the offset the rule transitions from.

  • to_offset (TimezoneOffset)

    the offset the rule transitions to.

  • year (Integer)

    the year when the transition occurs.

Returns:

[ GitHub ]

  
# File 'lib/tzinfo/annual_rules.rb', line 65

def apply_rule(rule, from_offset, to_offset, year)
  at = rule.at(from_offset, year)
  TimezoneTransition.new(to_offset, from_offset, at.value)
end

#transitions(year) ⇒ Array<TimezoneTransition>

Returns the transitions between standard and daylight savings time for a given year. The results are ordered by time of occurrence (earliest to latest).

Parameters:

  • year (Integer)

    the year to calculate transitions for.

Returns:

[ GitHub ]

  
# File 'lib/tzinfo/annual_rules.rb', line 49

def transitions(year)
  start_dst = apply_rule(@dst_start_rule, @std_offset, @dst_offset, year)
  end_dst = apply_rule(@dst_end_rule, @dst_offset, @std_offset, year)

  end_dst.timestamp_value < start_dst.timestamp_value ? [end_dst, start_dst] : [start_dst, end_dst]
end