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.
380 381 382 383 384 385 386 387 388 389 |
# File 'lib/tzinfo/timezone.rb', line 380 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.
377 378 379 |
# File 'lib/tzinfo/timezone.rb', line 377 def local_end @local_end end |
#local_start ⇒ Object (readonly)
Start time of the period (local time). May be nil if unbounded.
374 375 376 |
# File 'lib/tzinfo/timezone.rb', line 374 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.
366 367 368 |
# File 'lib/tzinfo/timezone.rb', line 366 def std_offset @std_offset end |
#utc_end ⇒ Object (readonly)
End time of the period (UTC). May be nil if unbounded.
358 359 360 |
# File 'lib/tzinfo/timezone.rb', line 358 def utc_end @utc_end end |
#utc_offset ⇒ Object (readonly)
Base offset of the timezone from UTC (seconds).
361 362 363 |
# File 'lib/tzinfo/timezone.rb', line 361 def utc_offset @utc_offset end |
#utc_start ⇒ Object (readonly)
Start time of the period (UTC). May be nil if unbounded.
355 356 357 |
# File 'lib/tzinfo/timezone.rb', line 355 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.
371 372 373 |
# File 'lib/tzinfo/timezone.rb', line 371 def zone_identifier @zone_identifier end |
Instance Method Details
#dst? ⇒ Boolean
true if daylight savings is in effect for this period; otherwise false.
402 403 404 |
# File 'lib/tzinfo/timezone.rb', line 402 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.
427 428 429 |
# File 'lib/tzinfo/timezone.rb', line 427 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.
432 433 434 |
# File 'lib/tzinfo/timezone.rb', line 432 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.
437 438 439 |
# File 'lib/tzinfo/timezone.rb', line 437 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.
442 443 444 |
# File 'lib/tzinfo/timezone.rb', line 442 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.
412 413 414 |
# File 'lib/tzinfo/timezone.rb', line 412 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.
417 418 419 |
# File 'lib/tzinfo/timezone.rb', line 417 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.
392 393 394 |
# File 'lib/tzinfo/timezone.rb', line 392 def utc_total_offset utc_offset + std_offset end |
#utc_total_offset_rational ⇒ Object
Total offset from UTC (days). Result is a Rational.
397 398 399 |
# File 'lib/tzinfo/timezone.rb', line 397 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.
422 423 424 |
# File 'lib/tzinfo/timezone.rb', line 422 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.
407 408 409 |
# File 'lib/tzinfo/timezone.rb', line 407 def valid_for_utc?(utc) utc_after_start?(utc) && utc_before_end?(utc) end |