Sha256: 73287b6de83493882815569a4468bc5fe91328b9dec8f70196c228cf41c898c1

Contents?: true

Size: 802 Bytes

Versions: 1

Compression:

Stored size: 802 Bytes

Contents

require "time"

module TimeBurlapIso8601
  # Burlap needs #iso8601 without any dashes or colons. It mimics the 1.8 implementation
  # of #iso8601, including not having a dependency on #strftime.
  # 
  # @param [Integer] fraction_digits number of digits of milliseconds wanted
  # @return [String] 
  # 
  def burlap_iso8601 fraction_digits=0
    sprintf("%d%02d%02dT%02d%02d%02d", year, mon, day, hour, min, sec) + \

    case fraction_digits
    when 0
      ""
    when 1..6
      sprintf(".%06d", usec)[0..3]
    else
      sprintf(".%06d", usec) + "0" * (fraction_digits - 6)
    end + \

    if utc?
      'Z'
    else
      off = utc_offset
      sign = off < 0 ? '-' : '+'
      sprintf('%s%02d:%02d', sign, *(off.abs / 60).divmod(60))
    end
  end
end

Time.send(:include, TimeBurlapIso8601)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
burlap-1.0.0 lib/core_ext/time_burlap_iso8601.rb