Class: TZInfo::TimezoneOffset
- Inherits:
-
Object
- Object
- TZInfo::TimezoneOffset
- Defined in:
- lib/tzinfo/timezone_offset.rb
Overview
Represents an offset from UTC observed by a time zone.
Instance Attribute Summary collapse
-
#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
). -
#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
).
Instance Method Summary collapse
-
#==(toi) ⇒ Boolean
Determines if this TimezoneOffset is equal to another instance.
-
#dst? ⇒ Boolean
Determines if daylight savings is in effect (i.e. if #std_offset is non-zero).
-
#eql?(toi) ⇒ Boolean
Determines if this TimezoneOffset is equal to another instance.
-
#hash ⇒ Integer
A hash based on #utc_offset, #std_offset and #abbreviation.
-
#initialize(base_utc_offset, std_offset, abbreviation) ⇒ TimezoneOffset
constructor
Initializes a new TimezoneOffset.
-
#inspect ⇒ String
The internal object state as a programmer-readable
String
.
Constructor Details
#initialize(base_utc_offset, std_offset, abbreviation) ⇒ TimezoneOffset
Initializes a new TZInfo::TimezoneOffset.
TZInfo::TimezoneOffset instances should not normally be constructed manually.
The passed in abbreviation
instance will be frozen.
62 63 64 65 66 67 68 |
# 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
#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.
50 51 52 |
# File 'lib/tzinfo/timezone_offset.rb', line 50 def abbreviation @abbreviation end |
#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.
21 22 23 |
# File 'lib/tzinfo/timezone_offset.rb', line 21 def base_utc_offset @base_utc_offset 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.
43 44 45 |
# File 'lib/tzinfo/timezone_offset.rb', line 43 def observed_utc_offset @observed_utc_offset end |
#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.
37 38 39 |
# File 'lib/tzinfo/timezone_offset.rb', line 37 def std_offset @std_offset end |
Instance Method Details
#==(toi) ⇒ Boolean
Determines if this TZInfo::TimezoneOffset is equal to another instance.
84 85 86 87 |
# 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 |
#dst? ⇒ Boolean
Determines if daylight savings is in effect (i.e. if #std_offset is non-zero).
74 75 76 |
# File 'lib/tzinfo/timezone_offset.rb', line 74 def dst? @std_offset != 0 end |
#eql?(toi) ⇒ Boolean
Determines if this TZInfo::TimezoneOffset is equal to another instance.
95 96 97 |
# File 'lib/tzinfo/timezone_offset.rb', line 95 def eql?(toi) self == toi end |
#hash ⇒ Integer
Returns a hash based on #utc_offset, #std_offset and #abbreviation.
101 102 103 |
# File 'lib/tzinfo/timezone_offset.rb', line 101 def hash [@base_utc_offset, @std_offset, @abbreviation].hash end |
#inspect ⇒ String
Returns the internal object state as a programmer-readable
String
.
107 108 109 |
# 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 |