Class: TZInfo::DateTimeWithOffset
- Includes:
- WithOffset
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb
Overview
A subclass of ‘DateTime` used to represent local times. DateTimeWithOffset 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, DateTimeWithOffset behaves identically to `DateTime`.
Arithmetic performed on DateTimeWithOffset 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 (‘offset`). The associated TimezoneOffset will aways be cleared.
Constant Summary
Constants inherited from DateTime
Instance Attribute Summary collapse
-
#timezone_offset ⇒ TimezoneOffset
readonly
The TimezoneOffset associated with this instance.
Instance Method Summary collapse
-
#downto(min) ⇒ Object
An overridden version of ‘DateTime#downto` that clears the associated TimezoneOffset of the returned or yielded instances.
-
#england ⇒ DateTime
An overridden version of ‘DateTime#england` that preserves the associated TimezoneOffset.
-
#gregorian ⇒ DateTime
An overridden version of ‘DateTime#gregorian` that preserves the associated TimezoneOffset.
-
#italy ⇒ DateTime
An overridden version of ‘DateTime#italy` that preserves the associated TimezoneOffset.
-
#julian ⇒ DateTime
An overridden version of ‘DateTime#julian` that preserves the associated TimezoneOffset.
-
#new_start(start = Date::ITALY) ⇒ DateTime
An overridden version of ‘DateTime#new_start` that preserves the associated TimezoneOffset.
-
#set_timezone_offset(timezone_offset) ⇒ DateTimeWithOffset
Sets the associated TimezoneOffset.
-
#step(limit, step = 1) ⇒ Object
An overridden version of ‘DateTime#step` that clears the associated TimezoneOffset of the returned or yielded instances.
-
#to_time ⇒ Time
An overridden version of ‘DateTime#to_time` that, if there is an associated TimezoneOffset, returns a DateTimeWithOffset with that offset.
-
#upto(max) ⇒ Object
An overridden version of ‘DateTime#upto` that clears the associated TimezoneOffset of the returned or yielded instances.
Methods included from WithOffset
Methods inherited from DateTime
#<=>, #acts_like_date?, #acts_like_time?, #advance, #ago, #as_json, #beginning_of_day, #beginning_of_hour, #beginning_of_minute, #blank?, #change, civil_from_format, current, #end_of_day, #end_of_hour, #end_of_minute, #formatted_offset, #localtime, #middle_of_day, #nsec, #readable_inspect, #seconds_since_midnight, #seconds_until_end_of_day, #since, #subsec, #to_default_s, #to_f, #to_fs, #to_i, #to_s, #usec, #utc, #utc?, #utc_offset
Instance Attribute Details
#timezone_offset ⇒ TimezoneOffset (readonly)
Returns the TimezoneOffset associated with this instance.
24 25 26 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 24 def timezone_offset @timezone_offset end |
Instance Method Details
#downto(min) ⇒ Object
An overridden version of ‘DateTime#downto` that clears the associated TimezoneOffset of the returned or yielded instances.
61 62 63 64 65 66 67 68 69 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 61 def downto(min) if block_given? super {|dt| yield dt.clear_timezone_offset } else enum = super enum.each {|dt| dt.clear_timezone_offset } enum end end |
#england ⇒ DateTime
An overridden version of ‘DateTime#england` that preserves the associated TimezoneOffset.
75 76 77 78 79 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 75 def england # super doesn't call #new_start on MRI, so each method has to be # individually overridden. if_timezone_offset(super) {|o,dt| dt.set_timezone_offset(o) } end |
#gregorian ⇒ DateTime
An overridden version of ‘DateTime#gregorian` that preserves the associated TimezoneOffset.
85 86 87 88 89 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 85 def gregorian # super doesn't call #new_start on MRI, so each method has to be # individually overridden. if_timezone_offset(super) {|o,dt| dt.set_timezone_offset(o) } end |
#italy ⇒ DateTime
An overridden version of ‘DateTime#italy` that preserves the associated TimezoneOffset.
95 96 97 98 99 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 95 def italy # super doesn't call #new_start on MRI, so each method has to be # individually overridden. if_timezone_offset(super) {|o,dt| dt.set_timezone_offset(o) } end |
#julian ⇒ DateTime
An overridden version of ‘DateTime#julian` that preserves the associated TimezoneOffset.
105 106 107 108 109 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 105 def julian # super doesn't call #new_start on MRI, so each method has to be # individually overridden. if_timezone_offset(super) {|o,dt| dt.set_timezone_offset(o) } end |
#new_start(start = Date::ITALY) ⇒ DateTime
An overridden version of ‘DateTime#new_start` that preserves the associated TimezoneOffset.
115 116 117 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 115 def new_start(start = Date::ITALY) if_timezone_offset(super) {|o,dt| dt.set_timezone_offset(o) } end |
#set_timezone_offset(timezone_offset) ⇒ DateTimeWithOffset
Sets the associated TimezoneOffset.
34 35 36 37 38 39 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 34 def set_timezone_offset(timezone_offset) raise ArgumentError, 'timezone_offset must be specified' unless timezone_offset raise ArgumentError, 'timezone_offset.observed_utc_offset does not match self.utc_offset' if offset * 86400 != timezone_offset.observed_utc_offset @timezone_offset = timezone_offset self end |
#step(limit, step = 1) ⇒ Object
An overridden version of ‘DateTime#step` that clears the associated TimezoneOffset of the returned or yielded instances.
121 122 123 124 125 126 127 128 129 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 121 def step(limit, step = 1) if block_given? super {|dt| yield dt.clear_timezone_offset } else enum = super enum.each {|dt| dt.clear_timezone_offset } enum end end |
#to_time ⇒ Time
An overridden version of ‘DateTime#to_time` that, if there is an associated TimezoneOffset, returns a TZInfo::DateTimeWithOffset with that offset.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 48 def to_time if_timezone_offset(super) do |o,t| # Ruby 2.4.0 changed the behaviour of to_time so that it preserves the # offset instead of converting to the system local timezone. # # When self has an associated TimezonePeriod, this implementation will # preserve the offset on all versions of Ruby. TimeWithOffset.at(t.to_i, t.subsec * 1_000_000).set_timezone_offset(o) end end |
#upto(max) ⇒ Object
An overridden version of ‘DateTime#upto` that clears the associated TimezoneOffset of the returned or yielded instances.
133 134 135 136 137 138 139 140 141 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/datetime_with_offset.rb', line 133 def upto(max) if block_given? super {|dt| yield dt.clear_timezone_offset } else enum = super enum.each {|dt| dt.clear_timezone_offset } enum end end |