Method: Time.xmlschema

Defined in:
lib/mtp.rb

.xmlschema(date) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/mtp.rb', line 226

def self.xmlschema(date)
  if /\A\s*
        (-?\d+)(\d\d)(\d\d)
        T
        (\d\d)(\d\d)(\d\d)?
        (\.\d*)?
        (Z|[+-]\d\d\d\d)?
        \s*\z/ix =~ date
    year = $1.to_i
    mon = $2.to_i
    day = $3.to_i
    hour = $4.to_i
    min = $5.to_i
    sec = $6.to_i
    usec = 0
    usec = $7.to_f * 1000000 if $7
    if $8
      zone = $8
      year, mon, day, hour, min, sec =
        apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
      Time.utc(year, mon, day, hour, min, sec, usec)
    else
        Time.local(year, mon, day, hour, min, sec, usec)
    end
  else
    raise ArgumentError.new("invalid date: #{date.inspect}")
  end
end