class Time
Public Instance Methods
to_api_decimal()
click to toggle source
Seconds as BigDecimal with precision to microseconds @return [BigDecimal]
# File lib/gb_date/time.rb, line 10 def to_api_decimal BigDecimal.new("#{self.to_i}.#{sprintf('%06d',self.nsec/1000)}") end
to_api_f()
click to toggle source
Seconds as Float with precision to microseconds @return [BigDecimal]
# File lib/gb_date/time.rb, line 16 def to_api_f self.to_api_decimal.to_f end
to_api_s()
click to toggle source
Return string with date represented by seconds with precision to microseconds @return [String]
# File lib/gb_date/time.rb, line 22 def to_api_s sprintf('%.6f', to_api_decimal) end
to_datetime()
click to toggle source
Converts time to DateTime
@return DateTime
# File lib/gb_date/time.rb, line 28 def to_datetime # Convert seconds + microseconds into a fractional number of seconds seconds = sec + Rational(usec, 10**6) # Convert a UTC offset measured in minutes to one measured in a # fraction of a day. offset = Rational(utc_offset, 60 * 60 * 24) DateTime.new(year, month, day, hour, min, seconds, offset) end
to_decimal()
click to toggle source
Seconds as BigDecimal @return [BigDecimal]
# File lib/gb_date/time.rb, line 4 def to_decimal BigDecimal.new("#{self.to_i}.#{sprintf('%09d',self.nsec)}") end