Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/time_ext.rb
Class Method Summary collapse
- .from_joda_time(gdatetime) ⇒ Object (also: from_gdata, from_date_time)
Instance Method Summary collapse
- #formatted_offset(colon = true, alternate_utc_string = nil) ⇒ Object
-
#iso8601(fraction_digits = 0) ⇒ Object
The following are copied from Rails.
- #to_joda_time ⇒ Object (also: #to_gdata, #to_date_time)
- #to_utc_offset_s(utc_offset, colon = true) ⇒ Object
Class Method Details
.from_joda_time(gdatetime) ⇒ Object Also known as: from_gdata, from_date_time
14 15 16 17 18 19 20 21 |
# File 'lib/time_ext.rb', line 14 def from_joda_time(gdatetime) if defined? parse self.parse(gdatetime.to_s) else res = ParseDate.parsedate(gdatetime.to_s) Time.local(*res) end end |
Instance Method Details
#formatted_offset(colon = true, alternate_utc_string = nil) ⇒ Object
37 38 39 |
# File 'lib/time_ext.rb', line 37 def formatted_offset(colon = true, alternate_utc_string = nil) utc? && alternate_utc_string || to_utc_offset_s(utc_offset, colon) end |
#iso8601(fraction_digits = 0) ⇒ Object
The following are copied from Rails. If you are using Rails, everything is already defined in ActiveSupport
30 31 32 33 34 35 |
# File 'lib/time_ext.rb', line 30 def iso8601(fraction_digits = 0) fraction = if fraction_digits > 0 ".%i" % self.usec.to_s[0, fraction_digits] end "#{self.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}" end |
#to_joda_time ⇒ Object Also known as: to_gdata, to_date_time
6 7 8 |
# File 'lib/time_ext.rb', line 6 def to_joda_time GDateTime.parseDateTime(self.iso8601) end |
#to_utc_offset_s(utc_offset, colon = true) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/time_ext.rb', line 41 def to_utc_offset_s(utc_offset, colon=true) seconds = utc_offset sign = (seconds < 0 ? -1 : 1) hours = seconds.abs / 3600 minutes = (seconds.abs % 3600) / 60 "%+03d%s%02d" % [ hours * sign, colon ? ":" : "", minutes ] end |