Class: TZInfo::TimestampWithOffset
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Timestamp
|
|
Instance Chain:
self,
WithOffset ,
Timestamp ,
Comparable
|
|
Inherits: |
TZInfo::Timestamp
|
Defined in: | lib/tzinfo/timestamp_with_offset.rb |
Overview
A subclass of Timestamp
used to represent local times.
TimestampWithOffset
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,
TimestampWithOffset
behaves identically to Timestamp
.
Constant Summary
Class Method Summary
-
.set_timezone_offset(timestamp, timezone_offset) ⇒ TimestampWithOffset
Creates a new
TimestampWithOffset
from a givenTimestamp
andTimezoneOffset
.
Timestamp
- Inherited
.create | Returns a new |
.for | |
.new | Initializes a new |
.utc | Creates a new UTC |
.for_datetime | Creates a |
.for_time | Creates a |
.for_time_like | Creates a |
.for_timestamp | |
.is_time_like? | Determines if an object is like a |
.new! |
Instance Attribute Summary
- #timezone_offset ⇒ TimezoneOffset readonly
Timestamp
- Inherited
Instance Method Summary
-
#set_timezone_offset(timezone_offset) ⇒ TimestampWithOffset
Sets the associated
TimezoneOffset
of thisTimestampWithOffset
. -
#to_datetime ⇒ DateTime
An overridden version of Timestamp#to_datetime, if there is an associated
TimezoneOffset
, returns aDateTimeWithOffset
with that offset. -
#to_time ⇒ Time
An overridden version of Timestamp#to_time that, if there is an associated
TimezoneOffset
, returns aTimeWithOffset
with that offset.
WithOffset
- Included
#strftime | Overrides the |
#if_timezone_offset | Performs a calculation if there is an associated |
Timestamp
- Inherited
#<=> | Compares this |
#add_and_set_utc_offset | Adds a number of seconds to the |
#eql?, #hash, #inspect, | |
#strftime | Formats this |
#to_datetime | Converts this |
#to_i | Converts this |
#to_s, | |
#to_time | Converts this |
#utc, | |
#new_datetime | Constructs a new instance of a |
#new_time | Creates a new instance of a |
#initialize! | Initializes a new |
#sub_second_to_s | Converts the |
#value_and_sub_second_to_s | Converts the value and sub-seconds to a |
Constructor Details
This class inherits a constructor from TZInfo::Timestamp
Class Method Details
.set_timezone_offset(timestamp, timezone_offset) ⇒ TimestampWithOffset
Creates a new TimestampWithOffset
from a given Timestamp
and
TimezoneOffset
.
time of timestamp
.
# File 'lib/tzinfo/timestamp_with_offset.rb', line 32
def self.set_timezone_offset(, timezone_offset) raise ArgumentError, 'timestamp must be specified' unless raise ArgumentError, 'timezone_offset must be specified' unless timezone_offset new!( .value, .sub_second, timezone_offset.observed_utc_offset).set_timezone_offset(timezone_offset) end
Instance Attribute Details
#timezone_offset ⇒ TimezoneOffset (readonly)
# File 'lib/tzinfo/timestamp_with_offset.rb', line 17
attr_reader :timezone_offset
Instance Method Details
#set_timezone_offset(timezone_offset) ⇒ TimestampWithOffset
Sets the associated TimezoneOffset
of this TimestampWithOffset
.
# File 'lib/tzinfo/timestamp_with_offset.rb', line 47
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 utc? || utc_offset != timezone_offset.observed_utc_offset @timezone_offset = timezone_offset self end
#to_datetime ⇒ DateTime
An overridden version of Timestamp#to_datetime, if there is an
associated TimezoneOffset
, returns a DateTimeWithOffset
with that
offset.
# File 'lib/tzinfo/timestamp_with_offset.rb', line 76
def to_datetime to = timezone_offset if to new_datetime(DateTimeWithOffset).set_timezone_offset(to) else super end end
#to_time ⇒ Time
An overridden version of Timestamp#to_time that, if there is an
associated TimezoneOffset
, returns a TimeWithOffset
with that offset.
# File 'lib/tzinfo/timestamp_with_offset.rb', line 60
def to_time to = timezone_offset if to new_time(TimeWithOffset).set_timezone_offset(to) else super end end