Class: TZInfo::TimezonePeriod Abstract

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

Overview

This class is abstract.

Time zone period data will returned as an instance of one of the subclasses of TimezonePeriod.

TimezonePeriod represents a period of time for a time zone where the same offset from UTC applies. It provides access to the observed offset, time zone abbreviation, start time and end time.

The period of time can be unbounded at the start, end, or both the start and end.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset) ⇒ TimezonePeriod

Initializes a TZInfo::TimezonePeriod.

Parameters:

  • offset (TimezoneOffset)

    the offset that is observed for the period of time.

Raises:

  • (ArgumentError)

    if offset is nil.



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

def initialize(offset)
  raise ArgumentError, 'offset must be specified' unless offset
  @offset = offset
end

Instance Attribute Details

#offsetTimezoneOffset (readonly)

Returns the offset that applies in the period of time.

Returns:



16
17
18
# File 'lib/tzinfo/timezone_period.rb', line 16

def offset
  @offset
end

Instance Method Details

#abbreviationString Also known as: abbr, zone_identifier

The abbreviation that identifies this offset. For example GMT (Greenwich Mean Time) or BST (British Summer Time) for Europe/London.

Returns:

  • (String)

    the abbreviation that identifies this offset.



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

def abbreviation
  @offset.abbreviation
end

#base_utc_offsetInteger Also known as: utc_offset

Returns the base offset from UTC in seconds (observed_utc_offset - std_offset). This does not include any adjustment made for daylight savings time and will typically remain constant throughout the year.

To obtain the currently observed offset from UTC, including the effect of daylight savings time, use #observed_utc_offset instead.

If you require accurate #base_utc_offset values, you should install the tzinfo-data gem and set DataSources::RubyDataSource as the DataSource. When using DataSources::ZoneinfoDataSource, the value of #base_utc_offset has to be derived from changes to the observed UTC offset and DST status since it is not included in zoneinfo files.

Returns:

  • (Integer)

    the base offset from UTC in seconds.



54
55
56
# File 'lib/tzinfo/timezone_period.rb', line 54

def base_utc_offset
  @offset.base_utc_offset
end

#dst?Boolean

Determines if daylight savings is in effect (i.e. if #std_offset is non-zero).

Returns:

  • (Boolean)

    true if #std_offset is non-zero, otherwise false.



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

def dst?
  @offset.dst?
end

#end_transitionTimezoneTransition

Returns the transition that defines the end of this TZInfo::TimezonePeriod (nil if the end is unbounded).

Returns:



36
37
38
# File 'lib/tzinfo/timezone_period.rb', line 36

def end_transition
  raise_not_implemented(:end_transition)
end

#ends_atTimestamp

Returns the UTC end time of the period or nil if the end of the period is unbounded.

The result is returned as a TZInfo::Timestamp. To obtain the end time as a Time or DateTime, call either to_time or to_datetime on the result.

Returns:

  • (Timestamp)

    the UTC end time of the period or nil if the end of the period is unbounded.



125
126
127
# File 'lib/tzinfo/timezone_period.rb', line 125

def ends_at
  timestamp(end_transition)
end

#local_ends_atTimestampWithOffset

Returns the local end time of the period or nil if the end of the period is unbounded.

The result is returned as a TZInfo::TimestampWithOffset. To obtain the end time as a Time or DateTime, call either to_time or to_datetime on the result.

Returns:

  • (TimestampWithOffset)

    the local end time of the period or nil if the end of the period is unbounded.



151
152
153
# File 'lib/tzinfo/timezone_period.rb', line 151

def local_ends_at
  timestamp_with_offset(end_transition)
end

#local_starts_atTimestampWithOffset

Returns the local start time of the period or nil if the start of the period is unbounded.

The result is returned as a TZInfo::TimestampWithOffset. To obtain the start time as a Time or DateTime, call either to_time or to_datetime on the result.

Returns:

  • (TimestampWithOffset)

    the local start time of the period or nil if the start of the period is unbounded.



138
139
140
# File 'lib/tzinfo/timezone_period.rb', line 138

def local_starts_at
  timestamp_with_offset(start_transition)
end

#observed_utc_offsetInteger Also known as: utc_total_offset

Returns the observed offset from UTC in seconds (base_utc_offset + std_offset). This includes adjustments made for daylight savings time.

Returns:

  • (Integer)

    the observed offset from UTC in seconds.



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

def observed_utc_offset
  @offset.observed_utc_offset
end

#start_transitionTimezoneTransition

Returns the transition that defines the start of this TZInfo::TimezonePeriod (nil if the start is unbounded).

Returns:



30
31
32
# File 'lib/tzinfo/timezone_period.rb', line 30

def start_transition
  raise_not_implemented(:start_transition)
end

#starts_atTimestamp

Returns the UTC start time of the period or nil if the start of the period is unbounded.

The result is returned as a TZInfo::Timestamp. To obtain the start time as a Time or DateTime, call either to_time or to_datetime on the result.

Returns:

  • (Timestamp)

    the UTC start time of the period or nil if the start of the period is unbounded.



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

def starts_at
  timestamp(start_transition)
end

#std_offsetInteger

Returns the offset from the time zone's standard time in seconds (observed_utc_offset - base_utc_offset). Zero when daylight savings time is not in effect. Non-zero (usually 3600 = 1 hour) if daylight savings is being observed.

If you require accurate #std_offset values, you should install the tzinfo-data gem and set DataSources::RubyDataSource as the DataSource. When using DataSources::ZoneinfoDataSource, the value of #std_offset has to be derived from changes to the observed UTC offset and DST status since it is not included in zoneinfo files.

Returns:

  • (Integer)

    the offset from the time zone's standard time in seconds.



72
73
74
# File 'lib/tzinfo/timezone_period.rb', line 72

def std_offset
  @offset.std_offset
end