Class: TimeCrisis::TZInfo::TimezoneOffsetInfo
- Defined in:
- lib/time_crisis/tzinfo/timezone_offset_info.rb
Overview
Represents an offset defined in a Timezone data file.
Instance Attribute Summary collapse
-
#abbreviation ⇒ Object
readonly
The abbreviation that identifies this observance, e.g.
-
#std_offset ⇒ Object
readonly
The offset from standard time for the zone in seconds (i.e. non-zero if daylight savings is being observed).
-
#utc_offset ⇒ Object
readonly
The base offset of the timezone from UTC in seconds.
-
#utc_total_offset ⇒ Object
readonly
The total offset of this observance from UTC in seconds (utc_offset + std_offset).
Instance Method Summary collapse
-
#==(toi) ⇒ Object
Returns true if and only if toi has the same utc_offset, std_offset and abbreviation as this TimezoneOffsetInfo.
-
#dst? ⇒ Boolean
True if std_offset is non-zero.
-
#eql?(toi) ⇒ Boolean
Returns true if and only if toi has the same utc_offset, std_offset and abbreviation as this TimezoneOffsetInfo.
-
#hash ⇒ Object
Returns a hash of this TimezoneOffsetInfo.
-
#initialize(utc_offset, std_offset, abbreviation) ⇒ TimezoneOffsetInfo
constructor
Constructs a new TimezoneOffsetInfo.
-
#inspect ⇒ Object
Returns internal object state as a programmer-readable string.
-
#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.
Constructor Details
#initialize(utc_offset, std_offset, abbreviation) ⇒ TimezoneOffsetInfo
Constructs a new TimezoneOffsetInfo. utc_offset and std_offset are specified in seconds.
23 24 25 26 27 28 29 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 23 def initialize(utc_offset, std_offset, abbreviation) @utc_offset = utc_offset @std_offset = std_offset @abbreviation = abbreviation @utc_total_offset = @utc_offset + @std_offset end |
Instance Attribute Details
#abbreviation ⇒ Object (readonly)
The abbreviation that identifies this observance, e.g. “GMT” (Greenwich Mean Time) or “BST” (British Summer Time) for “Europe/London”. The returned identifier is a symbol.
19 20 21 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 19 def abbreviation @abbreviation end |
#std_offset ⇒ Object (readonly)
The offset from standard time for the zone in seconds (i.e. non-zero if daylight savings is being observed).
10 11 12 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 10 def std_offset @std_offset end |
#utc_offset ⇒ Object (readonly)
The base offset of the timezone from UTC in seconds.
6 7 8 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 6 def utc_offset @utc_offset end |
#utc_total_offset ⇒ Object (readonly)
The total offset of this observance from UTC in seconds (utc_offset + std_offset).
14 15 16 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 14 def utc_total_offset @utc_total_offset end |
Instance Method Details
#==(toi) ⇒ Object
Returns true if and only if toi has the same utc_offset, std_offset and abbreviation as this TimezoneOffsetInfo.
52 53 54 55 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 52 def ==(toi) toi.respond_to?(:utc_offset) && toi.respond_to?(:std_offset) && toi.respond_to?(:abbreviation) && utc_offset == toi.utc_offset && std_offset == toi.std_offset && abbreviation == toi.abbreviation end |
#dst? ⇒ Boolean
True if std_offset is non-zero.
32 33 34 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 32 def dst? @std_offset != 0 end |
#eql?(toi) ⇒ Boolean
Returns true if and only if toi has the same utc_offset, std_offset and abbreviation as this TimezoneOffsetInfo.
59 60 61 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 59 def eql?(toi) self == toi end |
#hash ⇒ Object
Returns a hash of this TimezoneOffsetInfo.
64 65 66 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 64 def hash utc_offset.hash ^ std_offset.hash ^ abbreviation.hash end |
#inspect ⇒ Object
Returns internal object state as a programmer-readable string.
69 70 71 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 69 def inspect "#<#{self.class}: #@utc_offset,#@std_offset,#@abbreviation>" end |
#to_local(utc) ⇒ Object
Converts a UTC DateTime to local time based on the offset of this period.
37 38 39 40 41 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 37 def to_local(utc) TimeOrDateTime.wrap(utc) {|wrapped| wrapped + @utc_total_offset } end |
#to_utc(local) ⇒ Object
Converts a local DateTime to UTC based on the offset of this period.
44 45 46 47 48 |
# File 'lib/time_crisis/tzinfo/timezone_offset_info.rb', line 44 def to_utc(local) TimeOrDateTime.wrap(local) {|wrapped| wrapped - @utc_total_offset } end |