123456789_123456789_123456789_123456789_123456789_

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

Instance Attribute Summary

Instance Method Summary

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.

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.

[ GitHub ]

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

[ GitHub ]

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

alias abbr abbreviation

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

[ GitHub ]

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

attr_reader :abbreviation

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

[ GitHub ]

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

Returns:

  • (Boolean)

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

[ GitHub ]

  
# File 'lib/tzinfo/timezone_offset.rb', line 74

def dst?
  @std_offset != 0
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.

[ GitHub ]

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

attr_reader :observed_utc_offset

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

[ GitHub ]

  
# File 'lib/tzinfo/timezone_offset.rb', line 37

attr_reader :std_offset

#utc_offset (readonly)

Alias for #base_utc_offset.

[ GitHub ]

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

alias utc_offset base_utc_offset

#utc_total_offset (readonly)

[ GitHub ]

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

Parameters:

  • toi (Object)

    the instance to test for equality.

Returns:

[ GitHub ]

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

Parameters:

  • toi (Object)

    the instance to test for equality.

Returns:

[ GitHub ]

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

def eql?(toi)
  self == toi
end

#hashInteger

Returns:

[ GitHub ]

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

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

#inspectString

Returns:

  • (String)

    the internal object state as a programmer-readable String.

[ GitHub ]

  
# 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