Class: When::BasicTypes::Time

Inherits:
DateTime show all
Defined in:
lib/when_exe/basictypes.rb

Overview

ISO 8601 Time Representation

see xml schema

Class Method Summary collapse

Methods inherited from DateTime

_to_array

Methods inherited from String

#^, #calendar, #calendar_era, #calendar_note, #encode, #era, #ideographic_unification, #m17n, #ord, #resource, #to_m17n, #to_month_name, #to_pair, #to_r, #to_residue, #translate, #when?

Class Method Details

._to_array_basic(time, t, options = {}) ⇒ Object

基本形式の表現を分解して配列化する



298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/when_exe/basictypes.rb', line 298

def _to_array_basic(time, t, options={})
  return nil unless t
  return [0] unless time
  time.sub!(/,/, '.')
  unless (time =~ /^(\d{2}(?:\.\d+)?|-)(\d{2}(?:\.\d+)?|-)?(\d{2}(\.\d+)?)?$/)
    raise ArgumentError, "Wrong time format: #{time}"
  end
  indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
  abbr = Array(options[:abbr]).dup
  abbr[0..indices.length] = []
  return [0, Coordinates::Pair._en_number($1=='-' ? abbr[0] : $1, nil),
             Coordinates::Pair._en_number($2=='-' ? abbr[1] : $2, nil),
             Coordinates::Pair._en_number($3, nil)]
end

._to_array_extended(time, t, options = {}) ⇒ Object

拡張形式の表現を分解して配列化する



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/when_exe/basictypes.rb', line 314

def _to_array_extended(time, t, options={})
  return nil unless t
  return [0] unless time
  indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
  abbr = Array(options[:abbr]).dup
  abbr[0..indices.length] = []
  time.sub!(/,/, '.')
  tt = [0]
  while time =~ /^(\d{2}(?:\.\d+)?|-)([:*=])(.+)/
    time = $3
    tt << Coordinates::Pair._en_pair($1=='-' ? abbr.shift : $1, $2)
  end
  case time
  when /^(\d{2}(\.\d+)?)$/
    tt << Coordinates::Pair._en_number($1, nil)
  when ''
  else
    raise ArgumentError, "Wrong time format: #{time}"
  end
  return tt
end

._to_string_clock(clock) ⇒ Object

時間帯の表現を正規化する

Raises:

  • (ArgumentError)


337
338
339
340
341
342
343
# File 'lib/when_exe/basictypes.rb', line 337

def _to_string_clock(clock)
  return nil unless clock
  return clock if (clock =~ /^[A-Z]+$/)
  raise ArgumentError, "Wrong clock format: #{clock}" unless (clock =~ /^([-+])(\d{2})(?::?(\d{2}))?$/)
  s, h, m = $~[1..3]
  return s + h + ':' + (m||'00')
end