Class: TZInfo::TimezoneOffset
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/tzinfo/timezone_offset.rb |
Overview
Represents an offset from UTC observed by a time zone.
Class Method Summary
-
.new(base_utc_offset, std_offset, abbreviation) ⇒ TimezoneOffset
constructor
Initializes a new
TimezoneOffset
.
Instance Attribute Summary
-
#abbr
readonly
Alias for #abbreviation.
-
#abbreviation ⇒ String
(also: #abbr)
readonly
The abbreviation that identifies this offset.
-
#base_utc_offset ⇒ Integer
(also: #utc_offset)
readonly
Returns the base offset from UTC in seconds (
observed_utc_offset - std_offset
). -
#dst? ⇒ Boolean
readonly
Determines if daylight savings is in effect (i.e.
-
#observed_utc_offset ⇒ Integer
(also: #utc_total_offset)
readonly
Returns the observed offset from UTC in seconds (
base_utc_offset + std_offset
). -
#std_offset ⇒ Integer
readonly
Returns the offset from the time zone's standard time in seconds (
observed_utc_offset - base_utc_offset
). -
#utc_offset
readonly
Alias for #base_utc_offset.
-
#utc_total_offset
readonly
Alias for #observed_utc_offset.
Instance Method Summary
-
#==(toi) ⇒ Boolean
Determines if this
TimezoneOffset
is equal to another instance. -
#eql?(toi) ⇒ Boolean
Determines if this
TimezoneOffset
is equal to another instance. - #hash ⇒ Integer
- #inspect ⇒ String
Constructor Details
.new(base_utc_offset, std_offset, abbreviation) ⇒ TimezoneOffset
Initializes a new TimezoneOffset
.
TimezoneOffset
instances should not normally be constructed manually.
The passed in #abbreviation instance will be frozen.
# File 'lib/tzinfo/timezone_offset.rb', line 62
def initialize(base_utc_offset, std_offset, abbreviation) @base_utc_offset = base_utc_offset @std_offset = std_offset @abbreviation = abbreviation.freeze @observed_utc_offset = @base_utc_offset + @std_offset end
Instance Attribute Details
#abbr (readonly)
Alias for #abbreviation.
# File 'lib/tzinfo/timezone_offset.rb', line 51
alias abbr abbreviation
#abbreviation ⇒ String
(readonly)
Also known as: #abbr
The abbreviation that identifies this offset. For example GMT (Greenwich Mean Time) or BST (British Summer Time) for Europe/London.
# File 'lib/tzinfo/timezone_offset.rb', line 50
attr_reader :abbreviation
#base_utc_offset ⇒ Integer
(readonly)
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_offset.rb', line 21
attr_reader :base_utc_offset
#dst? ⇒ Boolean
(readonly)
Determines if daylight savings is in effect (i.e. if #std_offset is non-zero).
# File 'lib/tzinfo/timezone_offset.rb', line 74
def dst? @std_offset != 0 end
#observed_utc_offset ⇒ Integer
(readonly)
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_offset.rb', line 43
attr_reader :observed_utc_offset
#std_offset ⇒ Integer
(readonly)
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_offset.rb', line 37
attr_reader :std_offset
#utc_offset (readonly)
Alias for #base_utc_offset.
# File 'lib/tzinfo/timezone_offset.rb', line 22
alias utc_offset base_utc_offset
#utc_total_offset (readonly)
Alias for #observed_utc_offset.
# File 'lib/tzinfo/timezone_offset.rb', line 44
alias utc_total_offset observed_utc_offset
Instance Method Details
#==(toi) ⇒ Boolean
Determines if this TimezoneOffset
is equal to another instance.
# File 'lib/tzinfo/timezone_offset.rb', line 84
def ==(toi) toi.kind_of?(TimezoneOffset) && base_utc_offset == toi.base_utc_offset && std_offset == toi.std_offset && abbreviation == toi.abbreviation end
#eql?(toi) ⇒ Boolean
Determines if this TimezoneOffset
is equal to another instance.
# File 'lib/tzinfo/timezone_offset.rb', line 95
def eql?(toi) self == toi end
#hash ⇒ Integer
# File 'lib/tzinfo/timezone_offset.rb', line 101
def hash [@base_utc_offset, @std_offset, @abbreviation].hash end
#inspect ⇒ String
# File 'lib/tzinfo/timezone_offset.rb', line 107
def inspect "#<#{self.class}: @base_utc_offset=#{@base_utc_offset}, @std_offset=#{@std_offset}, @abbreviation=#{@abbreviation}>" end