class LibTAD::TADTime::TADDateTime
Date and time, split up into components.
Attributes
day[R]
@return [Integer] The day component of the timestamp.
hour[R]
@return [Integer] The hour component of the timestamp.
minute[R]
@return [Integer] The minute component of the timestamp.
month[R]
@return [Integer] The month component of the timestamp.
second[R]
@return [Integer] The second component of the timestamp.
year[R]
@return [Integer] The year component of the timestamp.
Public Class Methods
new(year: nil, month: nil, day: nil, hour: nil, minute: nil, second: nil)
click to toggle source
# File lib/types/time/datetime.rb, line 31 def initialize(year: nil, month: nil, day: nil, hour: nil, minute: nil, second: nil) @year = year @month = month @day = day @hour = hour @minute = minute @second = second end
Public Instance Methods
==(other)
click to toggle source
@return [Boolean] Compare equality to another instance.
# File lib/types/time/datetime.rb, line 42 def ==(other) other.year == @year && other.month == @month && other.day == @day && other.minute == @minute && other.second == @second end
from_json(hash)
click to toggle source
@return [::LibTAD::TADTime::TADDateTime] Helper function for initializing from json.
# File lib/types/time/datetime.rb, line 52 def from_json(hash) @year = hash&.fetch('year', nil) @month = hash&.fetch('month', nil) @day = hash&.fetch('day', nil) @hour = hash&.fetch('hour', nil) @minute = hash&.fetch('minute', nil) @second = hash&.fetch('second', nil) self end
now()
click to toggle source
@return [::LibTAD::TADTime::TADDateTime] Get the current time.
# File lib/types/time/datetime.rb, line 74 def now dt = ::Time.now @year = dt.year @month = dt.month @day = dt.day @hour = dt.hour @minute = dt.min @second = dt.sec self end
to_iso8601()
click to toggle source
@return [String] Helper function for formatting as ISO 8601.
# File lib/types/time/datetime.rb, line 65 def to_iso8601 year = @year.to_s.rjust(4, '0') month = @month.to_s.rjust(2, '0') day = @day.to_s.rjust(2, '0') "#{year}-#{month}-#{day}" end
to_std!()
click to toggle source
@return [::DateTime] Try converting to Time from the standard library.
# File lib/types/time/datetime.rb, line 88 def to_std! ::Time.new(@year, @month, @day, @hour, @minute, @second) end