class TZInfo::TimezoneTransition

Represents a transition from one timezone offset to another at a particular date and time.

Attributes

offset[R]

The offset this transition changes to (a TimezoneOffset instance).

previous_offset[R]

The offset this transition changes from (a TimezoneOffset instance).

Public Class Methods

new(offset, previous_offset) click to toggle source

Initializes a new TimezoneTransition.

TimezoneTransition instances should not normally be constructed manually.

# File lib/tzinfo/timezone_transition.rb, line 14
def initialize(offset, previous_offset)
  @offset = offset
  @previous_offset = previous_offset
  @local_end_at = nil
  @local_start_at = nil
end

Public Instance Methods

==(tti) click to toggle source

Returns true if this TimezoneTransition is equal to the given TimezoneTransition. Two TimezoneTransition instances are considered to be equal by == if offset, previous_offset and at are all equal.

# File lib/tzinfo/timezone_transition.rb, line 100
def ==(tti)
  tti.kind_of?(TimezoneTransition) &&
    offset == tti.offset && previous_offset == tti.previous_offset && at == tti.at
end
at() click to toggle source

A TimeOrDateTime instance representing the UTC time when this transition occurs.

# File lib/tzinfo/timezone_transition.rb, line 23
def at
  raise_not_implemented('at')
end
datetime() click to toggle source

The UTC time when this transition occurs, returned as a DateTime instance.

# File lib/tzinfo/timezone_transition.rb, line 28
def datetime
  at.to_datetime
end
eql?(tti) click to toggle source

Returns true if this TimezoneTransition is equal to the given TimezoneTransition. Two TimezoneTransition instances are considered to be equal by eql? if offset, previous_offset and at are all equal and the type used to define at in both instances is the same.

# File lib/tzinfo/timezone_transition.rb, line 109
def eql?(tti)
  tti.kind_of?(TimezoneTransition) &&
    offset == tti.offset && previous_offset == tti.previous_offset && at.eql?(tti.at)
end
hash() click to toggle source

Returns a hash of this TimezoneTransition instance.

# File lib/tzinfo/timezone_transition.rb, line 115
def hash
  @offset.hash ^ @previous_offset.hash ^ at.hash
end
inspect() click to toggle source

Returns internal object state as a programmer-readable string.

# File lib/tzinfo/timezone_transition.rb, line 120
def inspect
  "#<#{self.class}: #{at.inspect},#{@offset.inspect}>"      
end
local_end() click to toggle source

The local time when this transition causes the previous observance to end, returned as a DateTime instance.

# File lib/tzinfo/timezone_transition.rb, line 57
def local_end
  local_end_at.to_datetime
end
local_end_at() click to toggle source

A TimeOrDateTime instance representing the local time when this transition causes the previous observance to end (calculated from at using previous_offset).

# File lib/tzinfo/timezone_transition.rb, line 40
def local_end_at
  # Thread-safety: It is possible that the value of @local_end_at may be
  # calculated multiple times in concurrently executing threads. It is not
  # worth the overhead of locking to ensure that @local_end_at is only
  # calculated once.

  unless @local_end_at
    result = at.add_with_convert(@previous_offset.utc_total_offset)
    return result if frozen?
    @local_end_at = result
  end

  @local_end_at
end
local_end_time() click to toggle source

The local time when this transition causes the previous observance to end, returned as a Time instance.

# File lib/tzinfo/timezone_transition.rb, line 63
def local_end_time
  local_end_at.to_time
end
local_start() click to toggle source

The local time when this transition causes the next observance to start, returned as a DateTime instance.

# File lib/tzinfo/timezone_transition.rb, line 86
def local_start
  local_start_at.to_datetime
end
local_start_at() click to toggle source

A TimeOrDateTime instance representing the local time when this transition causes the next observance to start (calculated from at using offset).

# File lib/tzinfo/timezone_transition.rb, line 69
def local_start_at
  # Thread-safety: It is possible that the value of @local_start_at may be
  # calculated multiple times in concurrently executing threads. It is not
  # worth the overhead of locking to ensure that @local_start_at is only
  # calculated once.

  unless @local_start_at
    result = at.add_with_convert(@offset.utc_total_offset)
    return result if frozen?
    @local_start_at = result
  end

  @local_start_at
end
local_start_time() click to toggle source

The local time when this transition causes the next observance to start, returned as a Time instance.

# File lib/tzinfo/timezone_transition.rb, line 92
def local_start_time
  local_start_at.to_time
end
time() click to toggle source

The UTC time when this transition occurs, returned as a Time instance.

# File lib/tzinfo/timezone_transition.rb, line 33
def time
  at.to_time
end

Private Instance Methods

raise_not_implemented(method_name) click to toggle source
# File lib/tzinfo/timezone_transition.rb, line 126
def raise_not_implemented(method_name)
  raise NotImplementedError, "Subclasses must override #{method_name}"
end