Author Topic: Trouble with my GetNextWorkingDay udf  (Read 134 times)

gibberish

  • Newbie
  • *
  • Posts: 20
Trouble with my GetNextWorkingDay udf
« on: January 17, 2019, 06:38:29 am »
Any thoughts what is going on here?  I am getting occasional wacky results (see debug log below) from this GetNextWorkingDay udf.

The udfRemoveAlarm() fn will reschedule an alarm for the next working day if the message ends with *k

Here is the UDF (the *X has been stripped off and stored in a var called _rep):

Code: [Select]
elseif _rep == `d` || _rep == `k` || _rep == `x` || _rep == `l` ;x/l == Expiry after 20mins; k/l == (d)aily repeat but ONLY IF AT WORK
_newDT = udfGetNextWorkingDay(timeAdd(_oldDT, `0000:00:01:00:00:00`))
endif

_arrLen = arrInfo(_arrAlarms, 6)
arrayRedim(_arrAlarms, _arrLen+1)
_arrAlarms[_arrLen] = _newDT : `|` : _oldMsg ;zero-based, so _arrLen not _arrLen+1

              return _arrAlarms
        #ENDFUNCTION ;udfRemoveAlarm()
#DEFINEFUNCTION udfGetNextWorkingDay(_dt)
debugTrace(22)
_b = TimeJulianDay(_dt)
_c = (_b+5) mod 7
_day=ItemExtract(_c+1, `Sun Mon Tue Wed Thu Fri Sat`, ` `)
if _day == `Sat`
_newDate = timeAdd(_dt, `0000:00:02:00:00:00`)
elseif _day == `Sun`
_newDate = timeAdd(_dt, `0000:00:01:00:00:00`)
else
_newDate = _dt
endif
return _newDate
#ENDFUNCTION ;udfGetNextWorkingDay



Here is the debugtrace log:

Code: [Select]
to arrInfo(_arrAlarms,6)-1
(5080313) END OPERATOR

_tmp = _arrAlarms[_zqn]
(5080313) VALUE STRING => "2019:12:31:07:15:00|Prep News-RaviZacharias DVD for LaCouvee*k"

_doNutnZ = 0
(5080313) VALUE INT => 0

_doNutnQ = 0
(5080313) VALUE INT => 0

_doNutnP = 0
(5080313) VALUE INT => 0

if strIndex( _tmp, `*q`, 0, @FWDSCAN ) > 0 then _doNutnQ = 1
(5080313) ==>FALSE=> (skipped)

if strIndex( _tmp, `*p`, 0, @FWDSCAN ) > 0 then _doNutnP = 1
(5080313) ==>FALSE=> (skipped)

ELSEIF strIndex( _tmp, `*`, 0, @FWDSCAN ) > 0
(5080313) ELSEIF DO==>TRUE

_arrRep = arrayize(_tmp, `*`)
(5080313) VALUE ARRAY => <array>

_arrOldAlarm = arrayize(_tmp,`|`)
(5080313) VALUE ARRAY => <array>

_oldDT = _arrOldAlarm[0]
(5080313) VALUE STRING => "2019:12:31:07:15:00"

_oldMsg = _arrOldAlarm[1]
(5080313) VALUE STRING => "Prep News-RaviZacharias DVD for LaCouvee*k"

_rep = strLower(_arrRep[1])
(5080313) VALUE STRING => "k"

elseif _rep == `d` || _rep == `k` || _rep == `x` || _rep == `l` ;x/l == Expiry after 20mins
(5080313) ELSEIF DO==>TRUE

_newDT = udfGetNextWorkingDay(timeAdd(_oldDT, `0000:00:01:00:00:00`))
(5080313) CALLING UDF (udfgetnextworkingday)

--- (5080329) In UDF (udfgetnextworkingday) ---
Tue 15/01/2019 3:04:18 PM

_b = TimeJulianDay(_dt)
(5080329) VALUE INT => 737791

_c = (_b+5) mod 7
(5080329) VALUE INT => 3

_day=ItemExtract(_c+1, `Sun Mon Tue Wed Thu Fri Sat`, ` `)
(5080329) VALUE STRING => "Wed"

if _day == `Sat`
(5080329) ELSE DO==>TRUE

_newDate = _dt
(5080329) VALUE STRING => "2020:01:01:07:15:00"

endif
(5080329) END OPERATOR

return _newDate
(5080329) RETURN VALUE STRING => "2020:01:01:07:15:00"

--- Leaving UDF (udfgetnextworkingday) ---

RETURNING FROM UDF (udfgetnextworkingday)

--- (5080329) In UDF (udfremovealarm) ---
Tue 15/01/2019 3:04:18 PM

_newDT = udfGetNextWorkingDay(timeAdd(_oldDT, `0000:00:01:00:00:00`))
(5080329) RETURN VALUE STRING => "2020:01:01:07:15:00"


What confuzzles me is that most of the time it works, but it has begun randomly (?) returning very wrong return dates. I've been getting years like 2037, 4372, etc. The returned date format is always correct (YYYY:MM:DD:HH:MM:SS), but the dates are random. It seems to mess up one date at a time. The alarms array (read in from below text file) looks like this:

Code: [Select]
2019:01:19:07:38:00|If no Mnrl on line, and no Mnrl CIRCUIT, take 1st Mnrl from Prods table*k
2019:01:17:07:35:00|PHP Email client*k
2019:01:18:07:15:00|OSidePW PHP Email contactform*k
2019:01:27:07:15:00|Prep News-RaviZacharias DVD for LaCouvee*k

gibberish

  • Newbie
  • *
  • Posts: 20
Re: Trouble with my GetNextWorkingDay udf
« Reply #1 on: January 17, 2019, 06:40:30 am »
I am using WB Compiler 2017B

td

  • Tech Support
  • *****
  • Posts: 2814
    • WinBatch
Re: Trouble with my GetNextWorkingDay udf
« Reply #2 on: January 17, 2019, 07:28:54 am »
Unless you can provide some evidence to the contrary, the only explanation worth offering is garbage-in-garbage-out.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

gibberish

  • Newbie
  • *
  • Posts: 20
Re: Trouble with my GetNextWorkingDay udf
« Reply #3 on: January 17, 2019, 07:58:42 am »
Yeah, you're right... I'll double-check what's being received as param in function. Thanks Tony.

stanl

  • Pundit
  • *****
  • Posts: 875
Re: Trouble with my GetNextWorkingDay udf
« Reply #4 on: January 17, 2019, 12:36:32 pm »
So the problem is it is returning a valid date, just a weird date, or does the script fail?