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, #clock, #encode, #era, #ideographic_unification, #m17n, #ord, #resource, #to_m17n, #to_month_name, #to_pair, #to_r, #to_residue, #translate, #when?

Methods included from EncodingConversion

#+@, #-@, #to_external_encoding, #to_internal_encoding

Class Method Details

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

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



328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/when_exe/basictypes.rb', line 328

def _to_array_basic(time, t, options={})
  return nil unless t
  return [0] unless time
  time.sub!(/,/, '.')
  unless (time =~ /\A(\d{2}(?:\.\d+)?|-)(\d{2}(?:\.\d+)?|-)?(\d{2}(\.\d+)?)?\z/)
    raise ArgumentError, "Wrong time format: #{time}"
  end
  indices = options[:frame] ? When.Calendar(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

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



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/when_exe/basictypes.rb', line 344

def _to_array_extended(time, t, options={})
  return nil unless t
  return [0] unless time
  indices = options[:frame] ? When.Calendar(options[:frame]).indices : Coordinates::DefaultDateIndices
  abbr = Array(options[:abbr]).dup
  abbr[0..indices.length] = []
  time.sub!(/,/, '.')
  if time =~ /\A([:*=])(.+)/
    time = $2
    tt = [Coordinates::Pair._en_pair(0, $1)]
  else
    tt = [0]
  end
  while time =~ /\A(\d{2}(?:\.\d+)?|-)([:*=])(.+)/
    time = $3
    tt << Coordinates::Pair._en_pair($1=='-' ? abbr.shift : $1, $2)
  end
  case time
  when /\A(\d{2}(\.\d+)?)\z/
    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)


372
373
374
375
376
377
378
379
380
# File 'lib/when_exe/basictypes.rb', line 372

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