Sha256: e1a4ce09d2d668c7247a7be40bf009d7a3bcadf51f2addbd0573e6467cd9bd34

Contents?: true

Size: 489 Bytes

Versions: 1

Compression:

Stored size: 489 Bytes

Contents

class DateTime
  RCAP_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S"
  RCAP_ZONE_FORMAT = "%+03i:00"

  alias inspect to_s

  # Returns a string representaion of the time suitable for CAP.
  # @return [String]
  # @example 
  #   DateTime.now.to_s_for_cap # => "2011-10-26T21:45:00+02:00"
  def to_s_for_cap
    t = self.strftime( RCAP_TIME_FORMAT ) + format( RCAP_ZONE_FORMAT , utc_hours_offset )
    t.sub(/\+(00:\d\d)$/, '-\1')
  end

  private
  def utc_hours_offset
    self.offset * 24
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rcap-1.3.1 lib/extensions/date_time.rb