Class: TZInfo::TimezonePeriod
- Inherits:
-
Object
- Object
- TZInfo::TimezonePeriod
- Defined in:
- lib/tzinfo/timezone.rb
Overview
A period of time in a timezone where the same offset from UTC applies.
Instance Attribute Summary collapse
-
#local_end ⇒ Object
readonly
End time of the period (local time).
-
#local_start ⇒ Object
readonly
Start time of the period (local time).
-
#std_offset ⇒ Object
readonly
Offset from the local time where daylight savings is in effect (seconds).
-
#utc_end ⇒ Object
readonly
End time of the period (UTC).
-
#utc_offset ⇒ Object
readonly
Base offset of the timezone from UTC (seconds).
-
#utc_start ⇒ Object
readonly
Start time of the period (UTC).
-
#zone_identifier ⇒ Object
readonly
The identifier of this period, e.g.
Instance Method Summary collapse
-
#dst? ⇒ Boolean
true if daylight savings is in effect for this period; otherwise false.
-
#initialize(utc_start, utc_end, utc_offset, std_offset, zone_identifier) ⇒ TimezonePeriod
constructor
Initializes a new TimezonePeriod.
-
#local_after_start?(local) ⇒ Boolean
true if the given local DateTime is after the start of the period; otherwise false.
-
#local_before_end?(local) ⇒ Boolean
true if the given local DateTime is before the end of the period; otherwise false.
-
#to_local(utc) ⇒ Object
Converts a UTC DateTime to local time based on the offset of this period.
-
#to_utc(local) ⇒ Object
Converts a local DateTime to UTC based on the offset of this period.
-
#utc_after_start?(utc) ⇒ Boolean
true if the given utc DateTime is after the start of the period; otherwise false.
-
#utc_before_end?(utc) ⇒ Boolean
true if the given utc DateTime is before the end of the period; otherwise false.
-
#utc_total_offset ⇒ Object
Total offset from UTC (seconds).
-
#utc_total_offset_rational ⇒ Object
Total offset from UTC (days).
-
#valid_for_local?(local) ⇒ Boolean
true if this period is valid for the given local DateTime; otherwise false.
-
#valid_for_utc?(utc) ⇒ Boolean
true if this period is valid for the given utc DateTime; otherwise false.
Constructor Details
#initialize(utc_start, utc_end, utc_offset, std_offset, zone_identifier) ⇒ TimezonePeriod
Initializes a new TimezonePeriod.
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/tzinfo/timezone.rb', line 283 def initialize(utc_start, utc_end, utc_offset, std_offset, zone_identifier) @utc_start = utc_start @utc_end = utc_end @utc_offset = utc_offset @std_offset = std_offset @zone_identifier = zone_identifier @local_start = utc_start.nil? ? nil : to_local(utc_start) @local_end = utc_end.nil? ? nil : to_local(utc_end) end |
Instance Attribute Details
#local_end ⇒ Object (readonly)
End time of the period (local time). May be nil if unbounded.
280 281 282 |
# File 'lib/tzinfo/timezone.rb', line 280 def local_end @local_end end |
#local_start ⇒ Object (readonly)
Start time of the period (local time). May be nil if unbounded.
277 278 279 |
# File 'lib/tzinfo/timezone.rb', line 277 def local_start @local_start end |
#std_offset ⇒ Object (readonly)
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 become +1 hours.
269 270 271 |
# File 'lib/tzinfo/timezone.rb', line 269 def std_offset @std_offset end |
#utc_end ⇒ Object (readonly)
End time of the period (UTC). May be nil if unbounded.
261 262 263 |
# File 'lib/tzinfo/timezone.rb', line 261 def utc_end @utc_end end |
#utc_offset ⇒ Object (readonly)
Base offset of the timezone from UTC (seconds).
264 265 266 |
# File 'lib/tzinfo/timezone.rb', line 264 def utc_offset @utc_offset end |
#utc_start ⇒ Object (readonly)
Start time of the period (UTC). May be nil if unbounded.
258 259 260 |
# File 'lib/tzinfo/timezone.rb', line 258 def utc_start @utc_start end |
#zone_identifier ⇒ Object (readonly)
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.
274 275 276 |
# File 'lib/tzinfo/timezone.rb', line 274 def zone_identifier @zone_identifier end |
Instance Method Details
#dst? ⇒ Boolean
true if daylight savings is in effect for this period; otherwise false.
305 306 307 |
# File 'lib/tzinfo/timezone.rb', line 305 def dst? std_offset != 0 end |
#local_after_start?(local) ⇒ Boolean
true if the given local DateTime is after the start of the period; otherwise false.
330 331 332 |
# File 'lib/tzinfo/timezone.rb', line 330 def local_after_start?(local) @local_start.nil? || @local_start <= local end |
#local_before_end?(local) ⇒ Boolean
true if the given local DateTime is before the end of the period; otherwise false.
335 336 337 |
# File 'lib/tzinfo/timezone.rb', line 335 def local_before_end?(local) @local_end.nil? || @local_end > local end |
#to_local(utc) ⇒ Object
Converts a UTC DateTime to local time based on the offset of this period.
340 341 342 |
# File 'lib/tzinfo/timezone.rb', line 340 def to_local(utc) utc + utc_total_offset_rational end |
#to_utc(local) ⇒ Object
Converts a local DateTime to UTC based on the offset of this period.
345 346 347 |
# File 'lib/tzinfo/timezone.rb', line 345 def to_utc(local) local - utc_total_offset_rational end |
#utc_after_start?(utc) ⇒ Boolean
true if the given utc DateTime is after the start of the period; otherwise false.
315 316 317 |
# File 'lib/tzinfo/timezone.rb', line 315 def utc_after_start?(utc) @utc_start.nil? || @utc_start <= utc end |
#utc_before_end?(utc) ⇒ Boolean
true if the given utc DateTime is before the end of the period; otherwise false.
320 321 322 |
# File 'lib/tzinfo/timezone.rb', line 320 def utc_before_end?(utc) @utc_end.nil? || @utc_end > utc end |
#utc_total_offset ⇒ Object
Total offset from UTC (seconds). Equal to utc_offset + std_offset.
295 296 297 |
# File 'lib/tzinfo/timezone.rb', line 295 def utc_total_offset utc_offset + std_offset end |
#utc_total_offset_rational ⇒ Object
Total offset from UTC (days). Result is a Rational.
300 301 302 |
# File 'lib/tzinfo/timezone.rb', line 300 def utc_total_offset_rational Rational(utc_total_offset, 86400) end |
#valid_for_local?(local) ⇒ Boolean
true if this period is valid for the given local DateTime; otherwise false.
325 326 327 |
# File 'lib/tzinfo/timezone.rb', line 325 def valid_for_local?(local) local_after_start?(local) && local_before_end?(local) end |
#valid_for_utc?(utc) ⇒ Boolean
true if this period is valid for the given utc DateTime; otherwise false.
310 311 312 |
# File 'lib/tzinfo/timezone.rb', line 310 def valid_for_utc?(utc) utc_after_start?(utc) && utc_before_end?(utc) end |