Parent

Files

TZInfo::TimezoneOffset

Represents an offset defined in a Timezone data file.

Attributes

abbreviation[R]

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.

std_offset[R]

The offset from standard time for the zone in seconds (i.e. non-zero if daylight savings is being observed).

utc_offset[R]

The base offset of the timezone from UTC in seconds.

utc_total_offset[R]

The total offset of this observance from UTC in seconds (utc_offset + std_offset).

Public Class Methods

new(utc_offset, std_offset, abbreviation) click to toggle source

Constructs a new TimezoneOffset. utc_offset and std_offset are specified in seconds.

# File lib/tzinfo/timezone_offset.rb, line 22
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

Public Instance Methods

==(toi) click to toggle source

Returns true if and only if toi has the same utc_offset, std_offset and abbreviation as this TimezoneOffset.

# File lib/tzinfo/timezone_offset.rb, line 53
def ==(toi)
  toi.kind_of?(TimezoneOffset) &&
    utc_offset == toi.utc_offset && std_offset == toi.std_offset && abbreviation == toi.abbreviation
end
dst?() click to toggle source

True if std_offset is non-zero.

# File lib/tzinfo/timezone_offset.rb, line 31
def dst?
  @std_offset != 0
end
eql?(toi) click to toggle source

Returns true if and only if toi has the same utc_offset, std_offset and abbreviation as this TimezoneOffset.

# File lib/tzinfo/timezone_offset.rb, line 60
def eql?(toi)
  self == toi
end
hash() click to toggle source

Returns a hash of this TimezoneOffset.

# File lib/tzinfo/timezone_offset.rb, line 65
def hash
  utc_offset.hash ^ std_offset.hash ^ abbreviation.hash
end
inspect() click to toggle source

Returns internal object state as a programmer-readable string.

# File lib/tzinfo/timezone_offset.rb, line 70
def inspect
  "#<#{self.class}: #@utc_offset,#@std_offset,#@abbreviation>"
end
to_local(utc) click to toggle source

Converts a UTC Time, DateTime or integer timestamp to local time, based on the offset of this period.

# File lib/tzinfo/timezone_offset.rb, line 37
def to_local(utc)
  TimeOrDateTime.wrap(utc) {|wrapped|
    wrapped + @utc_total_offset
  }
end
to_utc(local) click to toggle source

Converts a local Time, DateTime or integer timestamp to UTC, based on the offset of this period.

# File lib/tzinfo/timezone_offset.rb, line 45
def to_utc(local)
  TimeOrDateTime.wrap(local) {|wrapped|
    wrapped - @utc_total_offset
  }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.