Method: When::TM::ClockTime#initialize

Defined in:
lib/when_exe/tmposition.rb

#initialize(time, options = {}) ⇒ ClockTime

オブジェクトの生成

Parameters:

  • time (String)

    ISO8601形式の時刻表現

  • time (Array<Numeric>)

    (日, 時, 分, 秒)

  • options (Hash) (defaults to: {})

    以下の通り

Options Hash (options):



1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
# File 'lib/when_exe/tmposition.rb', line 1397

def initialize(time, options={})
  # 参照系の取得
  @frame = options[:frame] || Clock.local_time
  @frame = When.Clock(@frame) if (@frame.kind_of?(String))
  options.delete(:frame)

  # 時刻表現の解読 ( Time Zone の解釈 )
  if (time.kind_of?(String))
    case time
    when /\A([-+])?(\d{2,}?):?(\d{2})?:?(\d{2}(\.\d+)?)?\z/
      sign, hh, mm, ss = $~[1..4]
      time = @frame._validate([0,0,0,0],
             [0,
              -(sign.to_s + "0" + hh.to_s).to_i,
              -(sign.to_s + "0" + mm.to_s).to_i,
              Pair._en_number(-(sign.to_s + "0" + ss.to_s).to_f)])
      time[0] = Pair.new(0, time[0].to_i) if (time[0] != 0)
    when /\AZ\z/
      time = [0,0,0,0]
    else
      raise ArgumentError, "Invalid Time Format"
    end
  end
  @clk_time = time

  # 分解能
  @precision = @frame._precision(time, options.delete(:precision))

  super(options)
end