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, #encode, #era, #ideographic_unification, #m17n, #pair, #resource, #to_m17n, #to_month_name, #to_r, #to_residue, #translate, #when?
Class Method Details
._to_array_basic(time, t, options = {}) ⇒ Object
基本形式の表現を分解して配列化する
274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/when_exe/basictypes.rb', line 274 def _to_array_basic(time, t, ={}) 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 = [:frame] ? [:frame].indices : Coordinates::DefaultDateIndex 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
拡張形式の表現を分解して配列化する
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/when_exe/basictypes.rb', line 290 def _to_array_extended(time, t, ={}) return nil unless t return [0] unless time indices = [:frame] ? [:frame].indices : Coordinates::DefaultDateIndex abbr = Array([: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
時間帯の表現を正規化する
313 314 315 316 317 318 319 |
# File 'lib/when_exe/basictypes.rb', line 313 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 |