Class: TZInfo::TimezoneTransition

Inherits:
Object
  • Object
show all
Defined in:
lib/tzinfo/timezone_transition.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset, previous_offset) ⇒ TimezoneTransition

Initializes a new TimezoneTransition.

TimezoneTransition instances should not normally be constructed manually.



36
37
38
39
40
41
# File 'lib/tzinfo/timezone_transition.rb', line 36

def initialize(offset, previous_offset)
  @offset = offset
  @previous_offset = previous_offset
  @local_end_at = nil
  @local_start_at = nil
end

Instance Attribute Details

#offsetObject (readonly)

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



28
29
30
# File 'lib/tzinfo/timezone_transition.rb', line 28

def offset
  @offset
end

#previous_offsetObject (readonly)

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



31
32
33
# File 'lib/tzinfo/timezone_transition.rb', line 31

def previous_offset
  @previous_offset
end

Instance Method Details

#==(tti) ⇒ Object

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.



112
113
114
115
# File 'lib/tzinfo/timezone_transition.rb', line 112

def ==(tti)
  tti.kind_of?(TimezoneTransition) &&
    offset == tti.offset && previous_offset == tti.previous_offset && at == tti.at
end

#atObject

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

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/tzinfo/timezone_transition.rb', line 45

def at
  raise NotImplementedError, 'Subclasses must override at'
end

#datetimeObject

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



50
51
52
# File 'lib/tzinfo/timezone_transition.rb', line 50

def datetime
  at.to_datetime
end

#eql?(tti) ⇒ Boolean

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.

Returns:

  • (Boolean)


121
122
123
124
# File 'lib/tzinfo/timezone_transition.rb', line 121

def eql?(tti)
  tti.kind_of?(TimezoneTransition) &&
    offset == tti.offset && previous_offset == tti.previous_offset && at.eql?(tti.at)
end

#hashObject

Returns a hash of this TimezoneTransition instance.



127
128
129
# File 'lib/tzinfo/timezone_transition.rb', line 127

def hash
  @offset.hash ^ @previous_offset.hash ^ at.hash
end

#inspectObject

Returns internal object state as a programmer-readable string.



132
133
134
# File 'lib/tzinfo/timezone_transition.rb', line 132

def inspect
  "#<#{self.class}: #{at.inspect},#{@offset.inspect}>"      
end

#local_endObject

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



74
75
76
# File 'lib/tzinfo/timezone_transition.rb', line 74

def local_end
  local_end_at.to_datetime
end

#local_end_atObject

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



62
63
64
65
66
67
68
69
70
# File 'lib/tzinfo/timezone_transition.rb', line 62

def local_end_at
  # Thread-safey: 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.

  @local_end_at = at.add_with_convert(@previous_offset.utc_total_offset) unless @local_end_at
  @local_end_at
end

#local_end_timeObject

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



80
81
82
# File 'lib/tzinfo/timezone_transition.rb', line 80

def local_end_time
  local_end_at.to_time
end

#local_startObject

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



98
99
100
# File 'lib/tzinfo/timezone_transition.rb', line 98

def local_start
  local_start_at.to_datetime
end

#local_start_atObject

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



86
87
88
89
90
91
92
93
94
# File 'lib/tzinfo/timezone_transition.rb', line 86

def local_start_at
  # Thread-safey: 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.

  @local_start_at = at.add_with_convert(@offset.utc_total_offset) unless @local_start_at
  @local_start_at
end

#local_start_timeObject

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



104
105
106
# File 'lib/tzinfo/timezone_transition.rb', line 104

def local_start_time
  local_start_at.to_time
end

#timeObject

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



55
56
57
# File 'lib/tzinfo/timezone_transition.rb', line 55

def time
  at.to_time
end