123456789_123456789_123456789_123456789_123456789_

Class: TZInfo::LastDayOfMonthTransitionRule Private

Do not use. This class is for internal use only.
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

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