!******************************************************************************!
! Test the TIMEX and Time relative time for times less than one year
!
! @author Jeanette McCall / Zachary Matthews
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  invoke sec_per_day nxm.sys.lib.Time.SECONDS_PER_DAY
  call test_days_plus_minute_tostring
  call test_days_minus_minute_tostring
  call test_days_tostring
  call test_time_fromtostring
  call test_days_plus_minute_fromstring
  call test_days_minus_minute_fromstring
  call test_days_fromstring

endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Tests for EXPLAIN" msg.data eqss "PASS"
    pipe stop
  else
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
procedure test_days_plus_minute_tostring

  calc x 1 sec_per_day * 1 +     !Calc: X = 86401.0
  TIMEX x one_day
  invoke one_day_std one_day.toString()
  !res one_day_std
  assert/text="^reg.main.name: toString STD 1 day + 1 minute" one_day_std EQS "1::00:00:01.000"

  calc x 2 sec_per_day * 1 +     !Calc: X = 172801.0
  TIMEX x two_days
  invoke two_days_std two_days.toString()
  !res two_days_std
  assert/text="^reg.main.name: toString STD 2 days + 1 minute" two_days_std EQS "2::00:00:01.000"

  calc x 3 sec_per_day * 1 +     !Calc: X = 259201.0
  TIMEX x three_days
  invoke three_days_std three_days.toString()
  !res three_days_std
  assert/text="^reg.main.name: toString STD 3 days + 1 minute" three_days_std EQS "3::00:00:01.000"

  ! ACQ 2
  invoke one_day_acq one_day.toString(2,3)
  !res one_day_acq
  assert/text="^reg.main.name: toString ACQ 1 day + 1 minute" one_day_acq EQS "1:00:00:01.000"
  invoke two_days_acq two_days.toString(2,3)
  !res two_days_acq
  assert/text="^reg.main.name: toString ACQ 2 days + 1 minute" two_days_acq EQS "2:00:00:01.000"
  invoke three_days_acq three_days.toString(2,3)
  !res three_days_acq
  assert/text="^reg.main.name: toString ACQ 3 days + 1 minute" three_days_acq EQS "3:00:00:01.000"

  ! EPOCH 3
  invoke one_day_epoch one_day.toString(3,3)
  !res one_day_epoch
  assert/text="^reg.main.name: EPOCH 1 day + 1 minute" one_day_epoch EQS "86401.000"
  invoke two_days_epoch two_days.toString(3,3)
  !res two_days_epoch
  assert/text="^reg.main.name: toString EPOCH 2 days + 1 minute" two_days_epoch EQS "172801.000"
  invoke three_days_epoch three_days.toString(3,3)
  !res three_days_epoch
  assert/text="^reg.main.name: toString EPOCH 3 days + 1 minute" three_days_epoch EQS "259201.000"
return

!******************************************************************************!
procedure test_days_minus_minute_tostring

  calc x 2 sec_per_day * 1 -     !Calc: X = 172799.0
  TIMEX x two_days
  invoke two_days_std two_days.toString()
  !res two_days_std
  assert/text="^reg.main.name: toString STD 2 days - 1 minute" two_days_std EQS "1::23:59:59.000"

  calc x 3 sec_per_day * 1 -     !Calc: X = 259201.0
  TIMEX x three_days
  invoke three_days_std three_days.toString()
  !res three_days_std
  assert/text="^reg.main.name: toString STD 3 days - 1 minute" three_days_std EQS "2::23:59:59.000"

  ! ACQ 2
  invoke two_days_acq two_days.toString(2,3)
  !res two_days_acq
  assert/text="^reg.main.name: toString ACQ 2 days - 1 minute" two_days_acq EQS "1:23:59:59.000"
  invoke three_days_acq three_days.toString(2,3)
  !res three_days_acq
  assert/text="^reg.main.name: toString ACQ 3 days - 1 minute" three_days_acq EQS "2:23:59:59.000"

  ! EPOCH 3
  invoke two_days_epoch two_days.toString(3,3)
  !res two_days_epoch
  assert/text="^reg.main.name: toString EPOCH 2 days - 1 minute" two_days_epoch EQS "172799.000"
  invoke three_days_epoch three_days.toString(3,3)
  !res three_days_epoch
  assert/text="^reg.main.name: toString EPOCH 3 days - 1 minute" three_days_epoch EQS "259199.000"
return

!******************************************************************************!
procedure test_days_tostring

  calc x 1 sec_per_day *     !Calc: X = 86400.0
  TIMEX x one_day
  invoke one_day_std one_day.toString()
  assert/text="^reg.main.name: toString STD 1 day" one_day_std EQS "24:00:00.000"

  calc x 2 sec_per_day *     !Calc: X = 172800.0
  TIMEX x two_days
  invoke two_days_std two_days.toString()
  !res two_days_std
  assert/text="^reg.main.name: toString STD 2 days" two_days_std EQS "2::00:00:00.000"

  calc x 3 sec_per_day *     !Calc: X = 259200.0
  TIMEX x three_days
  invoke three_days_std three_days.toString()
  !res three_days_std
  assert/text="^reg.main.name: toString STD 3 days" three_days_std EQS "3::00:00:00.000"

    ! ACQ 2
  invoke one_day_acq one_day.toString(2,3)
  !res one_day_acq
  assert/text="^reg.main.name: toString ACQ 1 day" one_day_acq EQS "24:00:00.000"
  invoke two_days_acq two_days.toString(2,3)
  !res two_days_acq
  assert/text="^reg.main.name: toString ACQ 2 days" two_days_acq EQS "2:00:00:00.000"
  invoke three_days_acq three_days.toString(2,3)
  !res three_days_acq
  assert/text="^reg.main.name: toString ACQ 3 dayse" three_days_acq EQS "3:00:00:00.000"

  ! EPOCH 3
  invoke one_day_epoch one_day.toString(3,3)
  !res one_day_epoch
  assert/text="^reg.main.name: toString EPOCH 1 day" one_day_epoch EQS "86400.000"
  invoke two_days_epoch two_days.toString(3,3)
  !res two_days_epoch
  assert/text="^reg.main.name: toString EPOCH 2 days" two_days_epoch EQS "172800.000"
  invoke three_days_epoch three_days.toString(3,3)
  !res three_days_epoch
  assert/text="^reg.main.name: toString EPOCH 3 days" three_days_epoch EQS "259200.000"
return

!******************************************************************************!
procedure test_time_fromtostring

  new nxm.sys.lib.Time() mytime
  invoke ,, mytime.fromString("03:01::12:34:56.78")
  invoke mytime_std mytime.toString()
  assert/text="^reg.main.name: time fromString toString STD - month:day" mytime_std EQS "59::12:34:56.780"

  invoke ,, mytime.fromString("59::12:34:56.78")
  invoke mytime_std mytime.toString()
  assert/text="^reg.main.name: time fromString toString STD - day only" mytime_std EQS "59::12:34:56.780"

  invoke ,, mytime.fromString("59:12:34:56.780",2)
  invoke mytime_acq mytime.toString(2,3)
  assert/text="^reg.main.name: time fromString toString ACQ" mytime_acq EQS "59:12:34:56.780"
  
  invoke ,, mytime.fromString("5229296.780",3)
  invoke mytime_epoch mytime.toString(3,3)
  assert/text="^reg.main.name: time fromString toString EPOCH" mytime_epoch EQS "5229296.780"

  invoke ,, mytime.fromString("04:11::00:00:00.000")
  invoke mytime_std mytime.toString()
  assert/text="^reg.main.name: time fromString toString STD - 100 days - month:day" mytime_std EQS "100::00:00:00.000"

  invoke ,, mytime.fromString("100::00:00:00.000")
  invoke mytime_std mytime.toString()
  assert/text="^reg.main.name: time fromString toString STD - 100 days - day only" mytime_std EQS "100::00:00:00.000"

  invoke ,, mytime.fromString("100:00:00:00.000",2)
  invoke mytime_acq mytime.toString(2,3)
  assert/text="^reg.main.name: time fromString toString ACQ - 100 days" mytime_acq EQS "100:00:00:00.000"
  
  invoke ,, mytime.fromString("8640000",3)
  invoke mytime_epoch mytime.toString(3,3)
  assert/text="^reg.main.name: time fromString toString EPOCH - 100 days" mytime_epoch EQS "8640000.000"
return
!******************************************************************************!
procedure test_days_plus_minute_fromstring

  new nxm.sys.lib.Time() one_day
  invoke ,, one_day.fromString("1::00:00:01.000")
  calc x 1 sec_per_day * 1 +     !Calc: X = 86401.0
  TIMEX one_day SEC=one_day_sec
  assert/text="^reg.main.name: fromString STD 1 day + 1 minute" one_day_sec EQ x
  invoke ,, one_day.fromString("1:00:00:01.000",2)
  TIMEX one_day SEC=one_day_sec
  assert/text="^reg.main.name: fromString ACQ 1 day + 1 minute" one_day_sec EQ x
  invoke ,, one_day.fromString("86401.000",3)
  TIMEX one_day SEC=one_day_sec
  assert/text="^reg.main.name: fromString EPOCH 1 day + 1 minute" one_day_sec EQ x

  new nxm.sys.lib.Time() two_days
  invoke ,, two_days.fromString("2::00:00:01.000")
  calc x 2 sec_per_day * 1 +     !Calc: X = 172801.0
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString STD 2 days + 1 minute" two_days_sec EQ x
  invoke ,, two_days.fromString("2:00:00:01.000", 2)
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString ACQ 2 days + 1 minute" two_days_sec EQ x
  invoke ,, two_days.fromString("172801.000", 3)
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString EPOCH 2 days + 1 minute" two_days_sec EQ x

  new nxm.sys.lib.Time() three_days
  invoke ,, three_days.fromString("3::00:00:01.000")
  calc x 3 sec_per_day * 1 +     !Calc: X = 259201.0
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString STD 3 days + 1 minute" three_days_sec EQ x
  invoke ,, three_days.fromString("3:00:00:01.000",2)
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString ACQ 3 days + 1 minute" three_days_sec EQ x
  invoke ,, three_days.fromString("259201.000",3)
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString EPOCH 3 days + 1 minute" three_days_sec EQ x
return
!******************************************************************************!
procedure test_days_minus_minute_fromstring

  new nxm.sys.lib.Time() two_days
  invoke ,, two_days.fromString("1::23:59:59.000")
  calc x 2 sec_per_day * 1 -     !Calc: X = 172799.0
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString STD 2 days - 1 minute" two_days_sec EQ x
  invoke ,, two_days.fromString("1:23:59:59.000", 2)
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString ACQ 2 days - 1 minute" two_days_sec EQ x
  invoke ,, two_days.fromString("172799.000", 3)
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString EPOCH 2 days - 1 minute" two_days_sec EQ x

  new nxm.sys.lib.Time() three_days
  invoke ,, three_days.fromString("2::23:59:59.000")
  calc x 3 sec_per_day * 1 -     !Calc: X = 259199.0
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString STD 3 days - 1 minute" three_days_sec EQ x
  invoke ,, three_days.fromString("2:23:59:59.000",2)
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString ACQ 3 days - 1 minute" three_days_sec EQ x
  invoke ,, three_days.fromString("259199.000",3)
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString EPOCH 3 days - 1 minute" three_days_sec EQ x
 
return

!******************************************************************************!
procedure test_days_fromstring

  new nxm.sys.lib.Time() one_day
  invoke ,, one_day.fromString("1::00:00:00.000")
  calc x 1 sec_per_day *    !Calc: X = 86400.0
  TIMEX one_day SEC=one_day_sec
  assert/text="^reg.main.name: fromString STD 1 day" one_day_sec EQ x
  invoke ,, one_day.fromString("1:00:00:00.000",2)
  TIMEX one_day SEC=one_day_sec
  assert/text="^reg.main.name: fromString ACQ 1 day" one_day_sec EQ x
  invoke ,, one_day.fromString("86400.000",3)
  TIMEX one_day SEC=one_day_sec
  assert/text="^reg.main.name: fromString EPOCH 1 day" one_day_sec EQ x

  new nxm.sys.lib.Time() two_days
  invoke ,, two_days.fromString("2::00:00:00.000")
  calc x 2 sec_per_day *    !Calc: X = 172800.0
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString STD 2 days" two_days_sec EQ x
  invoke ,, two_days.fromString("2:00:00:00.000", 2)
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString ACQ 2 days" two_days_sec EQ x
  invoke ,, two_days.fromString("172800.000", 3)
  TIMEX two_days SEC=two_days_sec
  assert/text="^reg.main.name: fromString EPOCH 2 days" two_days_sec EQ x

  new nxm.sys.lib.Time() three_days
  invoke ,, three_days.fromString("3::00:00:00.000")
  calc x 3 sec_per_day *   !Calc: X = 259200.0
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString STD 3 days" three_days_sec EQ x
  invoke ,, three_days.fromString("3:00:00:00.000",2)
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString ACQ 3 days" three_days_sec EQ x
  invoke ,, three_days.fromString("259200.000",3)
  TIMEX three_days SEC=three_days_sec
  assert/text="^reg.main.name: fromString EPOCH 3 days" three_days_sec EQ x
return