Class: When::BasicTypes::Time
- Defined in:
- lib/when_exe/basictypes.rb
Overview
ISO 8601 Time Representation
see xml schema
Class Method Summary collapse
-
._to_array_basic(time, t, options = {}) ⇒ Object
基本形式の表現を分解して配列化する.
-
._to_array_extended(time, t, options = {}) ⇒ Object
拡張形式の表現を分解して配列化する.
-
._to_string_clock(clock) ⇒ Object
時間帯の表現を正規化する.
Methods inherited from DateTime
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
基本形式の表現を分解して配列化する
360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/when_exe/basictypes.rb', line 360 def _to_array_basic(time, t, ={}) 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 = [:frame] ? When.Calendar([:frame]).indices : Coordinates::DefaultDateIndices abbr = Array([: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
拡張形式の表現を分解して配列化する
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/when_exe/basictypes.rb', line 376 def _to_array_extended(time, t, ={}) return nil unless t return [0] unless time indices = [:frame] ? When.Calendar([:frame]).indices : Coordinates::DefaultDateIndices abbr = Array([: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{1,2}(?:\.\d+)?|-)([:*=])(.+)/ time = $3 tt << Coordinates::Pair._en_pair($1=='-' ? abbr.shift : $1, $2) end case time when /\A(\d{1,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
時間帯の表現を正規化する
404 405 406 407 408 409 410 411 412 |
# File 'lib/when_exe/basictypes.rb', line 404 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 |