class TZInfo::TimeWithOffset

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/tzinfo/time_with_offset.rbs

class TZInfo::TimeWithOffset < TZInfo::Time
  def localtime: (*Array[Integer] args) -> untyped
end

(‘utc_offset`). The associated {TimezoneOffset} will aways be cleared.
arithmetic operations will always maintain the same offset from UTC
Regardless of whether transitions in the time zone are crossed, results of
Arithmetic performed on {TimeWithOffset} instances is not time zone-aware.
cleared, {TimeWithOffset} behaves identically to `Time`.
necessarily be valid for the result). Once the {TimezoneOffset} has been
clear the associated {TimezoneOffset} (if the {TimezoneOffset} would not
return results appropriate for the {TimezoneOffset}. Certain operations will
reference to the related {TimezoneOffset} and overrides various methods to
A subclass of `Time` used to represent local times. {TimeWithOffset} holds a

def clear_timezone_offset

Returns:
  • (TimeWithOffset) - `self`.
def clear_timezone_offset
  @timezone_offset = nil
  self
end

def dst?

Returns:
  • (Boolean) - `true` if daylight savings time is being observed,
def dst?
  to = timezone_offset
  to ? to.dst? : super
end

def getlocal(*args)

Returns:
  • (Time) - a representation of the {TimeWithOffset} using either the
def getlocal(*args)
  # JRuby < 9.3 returns a Time in all cases.
  # JRuby >= 9.3 returns a Time when called with no arguments and a
  # TimeWithOffset with a timezone_offset assigned when called with an
  # offset argument.
  result = super
  result.clear_timezone_offset if result.kind_of?(TimeWithOffset)
  result
end

def gmtime

Returns:
  • (TimeWithOffset) - `self`.
def gmtime
  super
  @timezone_offset = nil
  self
end

def localtime(*args)

Experimental RBS support (using type sampling data from the type_fusion project).

def localtime: (* args) -> untyped

This signature was generated using 2 samples from 1 application.

Returns:
  • (TimeWithOffset) - `self`.
def localtime(*args)
  super
  @timezone_offset = nil
  self
end

def round(ndigits = 0)

Returns:
  • (Time) - the rounded time.
def round(ndigits = 0)
  if_timezone_offset(super) {|o,t| self.class.at(t.to_i, t.subsec * 1_000_000).set_timezone_offset(o) }
end

def set_timezone_offset(timezone_offset)

Raises:
  • (ArgumentError) - if `timezone_offset` is `nil`.

Returns:
  • (TimeWithOffset) - `self`.

Parameters:
  • timezone_offset (TimezoneOffset) -- the {TimezoneOffset} to use to set
def set_timezone_offset(timezone_offset)
  raise ArgumentError, 'timezone_offset must be specified' unless timezone_offset
  localtime(timezone_offset.observed_utc_offset)
  @timezone_offset = timezone_offset
  self
end

def to_a

Returns:
  • (Array) - an `Array` representation of the {TimeWithOffset}.
def to_a
  if_timezone_offset(super) do |o,a|
    a[8] = o.dst?
    a[9] = o.abbreviation
    a
  end
end

def to_datetime

Returns:
  • (DateTime) - if there is an associated {TimezoneOffset}, a
def to_datetime
  if_timezone_offset(super) do |o,dt|
    offset = dt.offset
    result = DateTimeWithOffset.jd(dt.jd + dt.day_fraction - offset)
    result = result.new_offset(offset) unless offset == 0
    result.set_timezone_offset(o)
  end
end

def utc

Returns:
  • (TimeWithOffset) - `self`.
def utc
  super
  @timezone_offset = nil
  self
end

def zone

Returns:
  • (String) - the {TimezoneOffset#abbreviation abbreviation} of the
def zone
  to = timezone_offset
  to ? to.abbreviation : super
end