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.



14
15
16
17
18
19
# 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

Instance Attribute Details

#offsetObject (readonly)

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



6
7
8
# File 'lib/tzinfo/timezone_transition.rb', line 6

def offset
  @offset
end

#previous_offsetObject (readonly)

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



9
10
11
# File 'lib/tzinfo/timezone_transition.rb', line 9

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.



90
91
92
93
# File 'lib/tzinfo/timezone_transition.rb', line 90

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.



23
24
25
# File 'lib/tzinfo/timezone_transition.rb', line 23

def at
  raise_not_implemented('at')
end

#datetimeObject

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



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

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)


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

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.



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

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

#inspectObject

Returns internal object state as a programmer-readable string.



110
111
112
# File 'lib/tzinfo/timezone_transition.rb', line 110

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.



52
53
54
# File 'lib/tzinfo/timezone_transition.rb', line 52

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).



40
41
42
43
44
45
46
47
48
# 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.

  @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.



58
59
60
# File 'lib/tzinfo/timezone_transition.rb', line 58

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.



76
77
78
# File 'lib/tzinfo/timezone_transition.rb', line 76

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).



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

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.

  @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.



82
83
84
# File 'lib/tzinfo/timezone_transition.rb', line 82

def local_start_time
  local_start_at.to_time
end

#timeObject

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



33
34
35
# File 'lib/tzinfo/timezone_transition.rb', line 33

def time
  at.to_time
end