Class: TZInfo::TimeWithOffset

Inherits:
Time show all
Includes:
WithOffset
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb

Overview

A subclass of ‘Time` used to represent local times. TimeWithOffset holds a reference to the related TimezoneOffset and overrides various methods to return results appropriate for the TimezoneOffset. Certain operations will clear the associated TimezoneOffset (if the TimezoneOffset would not necessarily be valid for the result). Once the TimezoneOffset has been cleared, TimeWithOffset behaves identically to `Time`.

Arithmetic performed on TimeWithOffset instances is not time zone-aware. Regardless of whether transitions in the time zone are crossed, results of arithmetic operations will always maintain the same offset from UTC (‘utc_offset`). The associated TimezoneOffset will aways be cleared.

Constant Summary

Constants inherited from Time

Time::COMMON_YEAR_DAYS_IN_MONTH, Time::DATE_FORMATS, Time::NOT_SET

Constants included from DateAndTime::Calculations

DateAndTime::Calculations::DAYS_INTO_WEEK, DateAndTime::Calculations::WEEKEND_DAYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WithOffset

#strftime

Methods inherited from Time

===, #acts_like_time?, #advance, #ago, #as_json, at_with_coercion, #beginning_of_day, #beginning_of_hour, #beginning_of_minute, #blank?, #ceil, #change, #compare_with_coercion, current, days_in_month, days_in_year, #end_of_day, #end_of_hour, #end_of_minute, #eql_with_coercion, find_zone, find_zone!, #floor, #formatted_offset, #middle_of_day, #minus_with_coercion, #minus_with_duration, #next_day, #next_month, #next_year, #plus_with_duration, #prev_day, #prev_month, #prev_year, rfc3339, #sec_fraction, #seconds_since_midnight, #seconds_until_end_of_day, #since, #to_default_s, #to_fs, #to_s, #to_time, use_zone, zone, zone=

Methods included from DateAndTime::Calculations

#after?, #all_day, #all_month, #all_quarter, #all_week, #all_year, #before?, #beginning_of_month, #beginning_of_quarter, #beginning_of_week, #beginning_of_year, #days_ago, #days_since, #days_to_week_start, #end_of_month, #end_of_quarter, #end_of_week, #end_of_year, #future?, #last_month, #last_year, #monday, #months_ago, #months_since, #next_occurring, #next_quarter, #next_week, #next_weekday, #on_weekday?, #on_weekend?, #past?, #prev_occurring, #prev_quarter, #prev_week, #prev_weekday, #sunday, #today?, #tomorrow, #tomorrow?, #weeks_ago, #weeks_since, #years_ago, #years_since, #yesterday, #yesterday?

Methods included from DateAndTime::Zones

#in_time_zone

Instance Attribute Details

#timezone_offsetTimezoneOffset (readonly)

Returns the TZInfo::TimezoneOffset associated with this instance.

Returns:



21
22
23
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 21

def timezone_offset
  @timezone_offset
end

Instance Method Details

#dst?Boolean Also known as: isdst

An overridden version of ‘Time#dst?` that, if there is an associated TZInfo::TimezoneOffset, returns the result of calling dst? on that offset.

Returns:

  • (Boolean)

    ‘true` if daylight savings time is being observed, otherwise `false`.



43
44
45
46
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 43

def dst?
  to = timezone_offset
  to ? to.dst? : super
end

#getlocal(*args) ⇒ Time

An overridden version of ‘Time#getlocal` that clears the associated TZInfo::TimezoneOffset if the base implementation of `getlocal` returns a TZInfo::TimeWithOffset.

Returns:



55
56
57
58
59
60
61
62
63
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 55

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

#gmtimeTimeWithOffset

An overridden version of ‘Time#gmtime` that clears the associated TZInfo::TimezoneOffset.

Returns:



69
70
71
72
73
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 69

def gmtime
  super
  @timezone_offset = nil
  self
end

#localtime(*args) ⇒ TimeWithOffset

An overridden version of ‘Time#localtime` that clears the associated TZInfo::TimezoneOffset.

Returns:



79
80
81
82
83
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 79

def localtime(*args)
  super
  @timezone_offset = nil
  self
end

#round(ndigits = 0) ⇒ Time

An overridden version of ‘Time#round` that, if there is an associated TZInfo::TimezoneOffset, returns a TZInfo::TimeWithOffset preserving that offset.

Returns:

  • (Time)

    the rounded time.



89
90
91
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 89

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

#set_timezone_offset(timezone_offset) ⇒ TimeWithOffset

Marks this TZInfo::TimeWithOffset as a local time with the UTC offset of a given TZInfo::TimezoneOffset and sets the associated TZInfo::TimezoneOffset.

Parameters:

Returns:

Raises:

  • (ArgumentError)

    if ‘timezone_offset` is `nil`.



30
31
32
33
34
35
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 30

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

#to_aArray

An overridden version of ‘Time#to_a`. The `isdst` (index 8) and `zone` (index 9) elements of the array are set according to the associated TZInfo::TimezoneOffset.

Returns:



98
99
100
101
102
103
104
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 98

def to_a
  if_timezone_offset(super) do |o,a|
    a[8] = o.dst?
    a[9] = o.abbreviation
    a
  end
end

#to_datetimeDateTime

An overridden version of ‘Time#to_datetime` that, if there is an associated TZInfo::TimezoneOffset, returns a DateTimeWithOffset with that offset.

Returns:



135
136
137
138
139
140
141
142
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 135

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

#utcTimeWithOffset

An overridden version of ‘Time#utc` that clears the associated TZInfo::TimezoneOffset.

Returns:



110
111
112
113
114
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 110

def utc
  super
  @timezone_offset = nil
  self
end

#zoneString

An overridden version of ‘Time#zone` that, if there is an associated TZInfo::TimezoneOffset, returns the abbreviation of that offset.

Returns:



123
124
125
126
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/time_with_offset.rb', line 123

def zone
  to = timezone_offset
  to ? to.abbreviation : super
end