123456789_123456789_123456789_123456789_123456789_

Class: TZInfo::LastDayOfMonthTransitionRule Private

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: TZInfo::DayOfWeekTransitionRule
Defined in: lib/tzinfo/transition_rule.rb

Overview

A rule that transitions on the last occurrence of a particular day of week of a calendar month.

Class Method Summary

DayOfWeekTransitionRule - Inherited

.new

Initializes a new DayOfWeekTransitionRule.

TransitionRule - Inherited

.new

Initializes a new TransitionRule.

Instance Attribute Summary

DayOfWeekTransitionRule - Inherited

TransitionRule - Inherited

#transition_at

Returns the number of seconds after midnight local time on the day identified by the rule at which the transition occurs.

Instance Method Summary

  • #==(r) ⇒ Boolean (also: #eql?) Internal use only

    Determines if this LastDayOfMonthTransitionRule is equal to another instance.

  • #eql?(r)

    Alias for #==.

  • #get_day(offset, year) ⇒ Time protected Internal use only

    Returns a Time representing midnight local time on the day specified by the rule for the given offset and year.

DayOfWeekTransitionRule - Inherited

#==

Determines if this DayOfWeekTransitionRule is equal to another instance.

#eql?
#hash_args

TransitionRule - Inherited

#==

Determines if this TransitionRule is equal to another instance.

#at

Calculates the time of the transition from a given offset on a given year.

#eql?
#hash, #hash_args

Constructor Details

.new(month, day_of_week, transition_at = 0) ⇒ LastDayOfMonthTransitionRule

Initializes a new LastDayOfMonthTransitionRule.

Parameters:

  • month (Integer) —

    the month of the year when the transition occurs.

  • day_of_week (Integer) —

    the day of the week when the transition occurs. 0 is Sunday, 6 is Saturday.

  • transition_at (Integer) (defaults to: 0) —

    the time in seconds after midnight local time at which the transition occurs.

Raises:

  • (ArgumentError) —

    if transition_at is not an Integer.

  • (ArgumentError) —

    if month is not an Integer.

  • (ArgumentError) —

    if month is less than 1 or greater than 12.

  • (ArgumentError) —

    if day_of_week is not an Integer.

  • (ArgumentError) —

    if day_of_week is less than 0 or greater than 6.

[ GitHub ]

  
# File 'lib/tzinfo/transition_rule.rb', line 409

def initialize(month, day_of_week, transition_at = 0)
  super(month, day_of_week, transition_at)
end

Instance Method Details

#==(r) ⇒ Boolean Also known as: #eql?

Determines if this LastDayOfMonthTransitionRule is equal to another instance.

Parameters:

  • r (Object) —

    the instance to test for equality.

Returns:

  • (Boolean) —

    true if r is a LastDayOfMonthTransitionRule with the same transition_at, month and day of week as this LastDayOfMonthTransitionRule, otherwise false.

[ GitHub ]

  
# File 'lib/tzinfo/transition_rule.rb', line 420

def ==(r)
  super(r) && r.kind_of?(LastDayOfMonthTransitionRule)
end

#eql?(r)

Alias for #==.

[ GitHub ]

  
# File 'lib/tzinfo/transition_rule.rb', line 423

alias eql? ==

#get_day(offset, year) ⇒ Time (protected)

Returns a Time representing midnight local time on the day specified by the rule for the given offset and year.

Parameters:

  • offset (TimezoneOffset) —

    the current offset at the time of the transition.

  • year (Integer) —

    the year in which the transition occurs.

Returns:

  • (Time) —

    midnight local time on the day specified by the rule for the given offset and year.

[ GitHub ]

  
# File 'lib/tzinfo/transition_rule.rb', line 435

def get_day(offset, year)
  next_month = month + 1
  if next_month == 13
    year += 1
    next_month = 1
  end

  candidate = Time.new(year, next_month, 1, 0, 0, 0, offset.observed_utc_offset) - 86400
  diff = candidate.wday - day_of_week

  if diff < 0
    candidate - (diff + 7) * 86400
  elsif diff > 0
    candidate - diff * 86400
  else
    candidate
  end
end