Class: TZInfo::TimezoneOffset

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

Overview

Represents an offset from UTC observed by a time zone.

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • base_utc_offset (Integer)

    the base offset from UTC in seconds.

  • std_offset (Integer)

    the offset from standard time in seconds.

  • abbreviation (String)

    the abbreviation identifying the offset.



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

#abbreviationString (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.

Returns:

  • (String)

    the abbreviation that identifies this offset.



50
51
52
# File 'lib/tzinfo/timezone_offset.rb', line 50

def abbreviation
  @abbreviation
end

#base_utc_offsetInteger (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.

Returns:

  • (Integer)

    the base offset from UTC in seconds.



21
22
23
# File 'lib/tzinfo/timezone_offset.rb', line 21

def base_utc_offset
  @base_utc_offset
end

#observed_utc_offsetInteger (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.

Returns:

  • (Integer)

    the observed offset from UTC in seconds.



43
44
45
# File 'lib/tzinfo/timezone_offset.rb', line 43

def observed_utc_offset
  @observed_utc_offset
end

#std_offsetInteger (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.

Returns:

  • (Integer)

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



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.

Parameters:

  • toi (Object)

    the instance to test for equality.

Returns:



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).

Returns:

  • (Boolean)

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



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.

Parameters:

  • toi (Object)

    the instance to test for equality.

Returns:



95
96
97
# File 'lib/tzinfo/timezone_offset.rb', line 95

def eql?(toi)
  self == toi
end

#hashInteger

Returns a hash based on #utc_offset, #std_offset and #abbreviation.

Returns:



101
102
103
# File 'lib/tzinfo/timezone_offset.rb', line 101

def hash
  [@base_utc_offset, @std_offset, @abbreviation].hash
end

#inspectString

Returns the internal object state as a programmer-readable String.

Returns:

  • (String)

    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