Object
A period of time in a timezone where the same offset from UTC applies.
All the methods that take times accept instances of Time, DateTime or integer timestamps.
The TimezoneTransitionInfo that defines the start of this TimezonePeriod (may be nil if unbounded).
The TimezoneTransitionInfo that defines the end of this TimezonePeriod (may be nil if unbounded).
Initializes a new TimezonePeriod.
# File lib/tzinfo/timezone_period.rb, line 41 41: def initialize(start_transition, end_transition, offset = nil) 42: @start_transition = start_transition 43: @end_transition = end_transition 44: 45: if offset 46: raise ArgumentError, 'Offset specified with transitions' if @start_transition || @end_transition 47: @offset = offset 48: else 49: if @start_transition 50: @offset = @start_transition.offset 51: elsif @end_transition 52: @offset = @end_transition.previous_offset 53: else 54: raise ArgumentError, 'No offset specified and no transitions to determine it from' 55: end 56: end 57: 58: @utc_total_offset_rational = nil 59: end
Returns true if this TimezonePeriod is equal to p. This compares the start_transition, end_transition and offset using ==.
# File lib/tzinfo/timezone_period.rb, line 167 167: def ==(p) 168: p.respond_to?(:start_transition) && p.respond_to?(:end_transition) && 169: p.respond_to?(:offset) && start_transition == p.start_transition && 170: end_transition == p.end_transition && offset == p.offset 171: end
The identifier of this period, e.g. “GMT” (Greenwich Mean Time) or “BST” (British Summer Time) for “Europe/London“. The returned identifier is a symbol.
# File lib/tzinfo/timezone_period.rb, line 76 76: def abbreviation 77: @offset.abbreviation 78: end
true if daylight savings is in effect for this period; otherwise false.
# File lib/tzinfo/timezone_period.rb, line 117 117: def dst? 118: @offset.dst? 119: end
Returns true if this TimezonePeriods is equal to p. This compares the start_transition, end_transition and offset using eql?
# File lib/tzinfo/timezone_period.rb, line 175 175: def eql?(p) 176: p.respond_to?(:start_transition) && p.respond_to?(:end_transition) && 177: p.respond_to?(:offset) && start_transition.eql?(p.start_transition) && 178: end_transition.eql?(p.end_transition) && offset.eql?(p.offset) 179: end
Returns a hash of this TimezonePeriod.
# File lib/tzinfo/timezone_period.rb, line 182 182: def hash 183: result = @start_transition.hash ^ @end_transition.hash 184: result ^= @offset.hash unless @start_transition || @end_transition 185: result 186: end
Returns internal object state as a programmer-readable string.
# File lib/tzinfo/timezone_period.rb, line 189 189: def inspect 190: result = "#<#{self.class}: #{@start_transition.inspect},#{@end_transition.inspect}" 191: result << ",#{@offset.inspect}>" unless @start_transition || @end_transition 192: result + '>' 193: end
true if the given local DateTime is after the start of the period (inclusive); otherwise false.
# File lib/tzinfo/timezone_period.rb, line 145 145: def local_after_start?(local) 146: !@start_transition || @start_transition.local_start <= local 147: end
true if the given local DateTime is before the end of the period (exclusive); otherwise false.
# File lib/tzinfo/timezone_period.rb, line 151 151: def local_before_end?(local) 152: !@end_transition || @end_transition.local_end > local 153: end
The end time of the period in local time as a DateTime. May be nil if unbounded.
# File lib/tzinfo/timezone_period.rb, line 112 112: def local_end 113: @end_transition ? @end_transition.local_end.to_datetime : nil 114: end
The start time of the period in local time as a DateTime. May be nil if unbounded.
# File lib/tzinfo/timezone_period.rb, line 106 106: def local_start 107: @start_transition ? @start_transition.local_start.to_datetime : nil 108: end
Offset from the local time where daylight savings is in effect (seconds). E.g.: utc_offset could be -5 hours. Normally, std_offset would be 0. During daylight savings, std_offset would typically become +1 hours.
# File lib/tzinfo/timezone_period.rb, line 69 69: def std_offset 70: @offset.std_offset 71: end
Converts a UTC DateTime to local time based on the offset of this period.
# File lib/tzinfo/timezone_period.rb, line 156 156: def to_local(utc) 157: @offset.to_local(utc) 158: end
Converts a local DateTime to UTC based on the offset of this period.
# File lib/tzinfo/timezone_period.rb, line 161 161: def to_utc(local) 162: @offset.to_utc(local) 163: end
true if the given UTC DateTime is after the start of the period (inclusive); otherwise false.
# File lib/tzinfo/timezone_period.rb, line 128 128: def utc_after_start?(utc) 129: !@start_transition || @start_transition.at <= utc 130: end
true if the given UTC DateTime is before the end of the period (exclusive); otherwise false.
# File lib/tzinfo/timezone_period.rb, line 134 134: def utc_before_end?(utc) 135: !@end_transition || @end_transition.at > utc 136: end
The end time of the period in UTC as a DateTime. May be nil if unbounded.
# File lib/tzinfo/timezone_period.rb, line 100 100: def utc_end 101: @end_transition ? @end_transition.at.to_datetime : nil 102: end
Base offset of the timezone from UTC (seconds).
# File lib/tzinfo/timezone_period.rb, line 62 62: def utc_offset 63: @offset.utc_offset 64: end
The start time of the period in UTC as a DateTime. May be nil if unbounded.
# File lib/tzinfo/timezone_period.rb, line 95 95: def utc_start 96: @start_transition ? @start_transition.at.to_datetime : nil 97: end
Total offset from UTC (seconds). Equal to utc_offset + std_offset.
# File lib/tzinfo/timezone_period.rb, line 82 82: def utc_total_offset 83: @offset.utc_total_offset 84: end
Total offset from UTC (days). Result is a Rational.
# File lib/tzinfo/timezone_period.rb, line 87 87: def utc_total_offset_rational 88: unless @utc_total_offset_rational 89: @utc_total_offset_rational = OffsetRationals.rational_for_offset(utc_total_offset) 90: end 91: @utc_total_offset_rational 92: end
true if this period is valid for the given local DateTime; otherwise false.
# File lib/tzinfo/timezone_period.rb, line 139 139: def valid_for_local?(local) 140: local_after_start?(local) && local_before_end?(local) 141: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.