Class: TZInfo::TimezonePeriod Abstract
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/tzinfo/timezone_period.rb |
Overview
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.
Class Method Summary
-
.new(offset) ⇒ TimezonePeriod
constructor
Initializes a
TimezonePeriod
.
Instance Attribute Summary
-
#dst? ⇒ Boolean
readonly
Determines if daylight savings is in effect (i.e.
- #offset ⇒ TimezoneOffset readonly
Instance Method Summary
-
#abbr
Alias for #abbreviation.
-
#abbreviation ⇒ String
(also: #abbr, #zone_identifier)
The abbreviation that identifies this offset.
-
#base_utc_offset ⇒ Integer
(also: #utc_offset)
Returns the base offset from UTC in seconds (
observed_utc_offset - std_offset
). - #end_transition ⇒ TimezoneTransition
-
#ends_at ⇒ Timestamp
Returns the UTC end time of the period or
nil
if the end of the period is unbounded. -
#local_ends_at ⇒ TimestampWithOffset
Returns the local end time of the period or
nil
if the end of the period is unbounded. -
#local_starts_at ⇒ TimestampWithOffset
Returns the local start time of the period or
nil
if the start of the period is unbounded. -
#observed_utc_offset ⇒ Integer
(also: #utc_total_offset)
Returns the observed offset from UTC in seconds (
base_utc_offset + std_offset
). - #start_transition ⇒ TimezoneTransition
-
#starts_at ⇒ Timestamp
Returns the UTC start time of the period or
nil
if the start of the period is unbounded. -
#std_offset ⇒ Integer
Returns the offset from the time zone's standard time in seconds (
observed_utc_offset - base_utc_offset
). -
#utc_offset
Alias for #base_utc_offset.
-
#utc_total_offset
Alias for #observed_utc_offset.
-
#zone_identifier
Alias for #abbreviation.
-
#raise_not_implemented(method_name)
private
Raises a
NotImplementedError
to indicate that subclasses should override a method. - #timestamp(transition) ⇒ Timestamp private
- #timestamp_with_offset(transition) ⇒ TimestampWithOffset private
Constructor Details
.new(offset) ⇒ TimezonePeriod
Initializes a TimezonePeriod
.
Instance Attribute Details
#dst? ⇒ Boolean
(readonly)
Determines if daylight savings is in effect (i.e. if #std_offset is non-zero).
# File 'lib/tzinfo/timezone_period.rb', line 99
def dst? @offset.dst? end
#offset ⇒ TimezoneOffset (readonly)
# File 'lib/tzinfo/timezone_period.rb', line 16
attr_reader :offset
Instance Method Details
#abbr
Alias for #abbreviation.
# File 'lib/tzinfo/timezone_period.rb', line 83
alias abbr abbreviation
#abbreviation ⇒ String
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.
# File 'lib/tzinfo/timezone_period.rb', line 80
def abbreviation @offset.abbreviation end
#base_utc_offset ⇒ Integer
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.
# File 'lib/tzinfo/timezone_period.rb', line 54
def base_utc_offset @offset.base_utc_offset end
#end_transition ⇒ TimezoneTransition
# File 'lib/tzinfo/timezone_period.rb', line 36
def end_transition raise_not_implemented(:end_transition) end
#ends_at ⇒ Timestamp
Returns the UTC end time of the period or nil
if the end of the period
is unbounded.
The result is returned as a Timestamp
. To obtain the end time as a
Time
or DateTime
, call either to_time or
to_datetime on the result.
# File 'lib/tzinfo/timezone_period.rb', line 125
def ends_at (end_transition) end
#local_ends_at ⇒ TimestampWithOffset
Returns the local end time of the period or nil
if the end of the period
is unbounded.
The result is returned as a TimestampWithOffset
. To obtain the end time
as a Time
or DateTime
, call either to_time or to_datetime on the result.
# File 'lib/tzinfo/timezone_period.rb', line 151
def local_ends_at (end_transition) end
#local_starts_at ⇒ TimestampWithOffset
Returns the local start time of the period or nil
if the start of the
period is unbounded.
The result is returned as a TimestampWithOffset
. To obtain the start
time as a Time
or DateTime
, call either to_time or to_datetime on the result.
# File 'lib/tzinfo/timezone_period.rb', line 138
def local_starts_at (start_transition) end
#observed_utc_offset ⇒ Integer
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.
# File 'lib/tzinfo/timezone_period.rb', line 90
def observed_utc_offset @offset.observed_utc_offset end
#raise_not_implemented(method_name) (private)
Raises a NotImplementedError
to indicate that subclasses should override
a method.
# File 'lib/tzinfo/timezone_period.rb', line 161
def raise_not_implemented(method_name) raise NotImplementedError, "Subclasses must override #{method_name}" end
#start_transition ⇒ TimezoneTransition
# File 'lib/tzinfo/timezone_period.rb', line 30
def start_transition raise_not_implemented(:start_transition) end
#starts_at ⇒ Timestamp
Returns the UTC start time of the period or nil
if the start of the
period is unbounded.
The result is returned as a Timestamp
. To obtain the start time as a
Time
or DateTime
, call either to_time or
to_datetime on the result.
# File 'lib/tzinfo/timezone_period.rb', line 112
def starts_at (start_transition) end
#std_offset ⇒ Integer
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.
# File 'lib/tzinfo/timezone_period.rb', line 72
def std_offset @offset.std_offset end
#timestamp(transition) ⇒ Timestamp (private)
# File 'lib/tzinfo/timezone_period.rb', line 168
def (transition) transition ? transition.at : nil end
#timestamp_with_offset(transition) ⇒ TimestampWithOffset (private)
# File 'lib/tzinfo/timezone_period.rb', line 175
def (transition) transition ? TimestampWithOffset.set_timezone_offset(transition.at, offset) : nil end
#utc_offset
Alias for #base_utc_offset.
# File 'lib/tzinfo/timezone_period.rb', line 57
alias utc_offset base_utc_offset
#utc_total_offset
Alias for #observed_utc_offset.
# File 'lib/tzinfo/timezone_period.rb', line 93
alias utc_total_offset observed_utc_offset
#zone_identifier
Alias for #abbreviation.
# File 'lib/tzinfo/timezone_period.rb', line 84
alias zone_identifier abbreviation