Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/gb_date/time.rb
Instance Method Summary collapse
-
#to_api_decimal ⇒ BigDecimal
Seconds as BigDecimal with precision to microseconds.
-
#to_api_f ⇒ BigDecimal
Seconds as Float with precision to microseconds.
-
#to_api_s ⇒ String
Return string with date represented by seconds with precision to microseconds.
-
#to_datetime ⇒ Object
Converts time to DateTime.
-
#to_decimal ⇒ BigDecimal
Seconds as BigDecimal.
Instance Method Details
#to_api_decimal ⇒ BigDecimal
Seconds as BigDecimal with precision to microseconds
10 11 12 |
# 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 ⇒ BigDecimal
Seconds as Float with precision to microseconds
16 17 18 |
# File 'lib/gb_date/time.rb', line 16 def to_api_f self.to_api_decimal.to_f end |
#to_api_s ⇒ String
Return string with date represented by seconds with precision to microseconds
22 23 24 |
# File 'lib/gb_date/time.rb', line 22 def to_api_s sprintf('%.6f', to_api_decimal) end |
#to_datetime ⇒ Object
Converts time to DateTime
28 29 30 31 32 33 34 35 36 |
# 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 ⇒ BigDecimal
Seconds as BigDecimal
4 5 6 |
# File 'lib/gb_date/time.rb', line 4 def to_decimal BigDecimal.new("#{self.to_i}.#{sprintf('%09d',self.nsec)}") end |