Skip to content

Commit

Permalink
Added functionality
Browse files Browse the repository at this point in the history
New Time funtionality and EvalBat_Debug.bat for help debugging
  • Loading branch information
adisak committed Apr 19, 2023
1 parent 4f3a231 commit 8427f00
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
15 changes: 15 additions & 0 deletions scripts/EvalBat_Debug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@echo off
REM "EvalBat" is a helper that lets you evaluate (vbscript) expressions in a batch file
REM "EvalBat" can be used to add floating point support and complex math support to batch files
REM Copyright (c) 2020-2022 Adisak Pochanayon
REM Contact: adisak@gmail.com
REM See EvalBat_License.txt for details
REM Currently hosted at https://github.com/adisak/EvalBat

REM -----------------------------------

echo Input: %*
call "%~dp0\EvalBat.bat" %*
echo Result: %EVALBAT_RESULT%

cscript.exe /nologo //X "%~dp0\EvalBat_vbs.vbs" "%*"
60 changes: 60 additions & 0 deletions scripts/EvalBat_vbs.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,66 @@ Function ExpN(X,N)
ExpN = Exp(X * Log(N))
End Function

REM Can convert ''%DATE%'' to a VBS Date
REM In US, %DATE% format looks like "Wed 04/19/2023"
REM May not work outside of US
Function DosDate(inDate)
Dim ssDate
ssDate=Split(inDate)
DosDate = DateValue(ssDate(1))
End Function

REM Can convert ''%TIME%'' to a VBS Time
REM In US, %TIME% format looks like "13:11:06.75"
REM VBScript doesn't like the decimal and hundreds in the seconds portion
Function DosTime(inTime)
Dim ssTime
ssTime=Split(inTime,".")
DosTime = TimeValue(ssTime(0))
End Function

REM Convert N seconds to HH:MM:SS.ss format
Function SecToHMSX(inSec)
Dim workTime,secFrac,ss,mm,hh,timestring
workTime = Int(inSec)
secFrac = inSec - Int(inSec)
ss = workTime MOD 60
workTime = (workTime - ss) / 60
mm = workTime MOD 60
hh = (workTime - mm) / 60
REM Format the time string
timestring = CStr(hh) + ":"
If mm < 10 Then
timestring = timestring + "0"
End If
timestring = timestring + CStr(mm) + ":"
If ss < 10 Then
timestring = timestring + "0"
End If
timestring = timestring + FormatNumber(ss+secFrac,2,true)
SecToHMSX = timestring
End Function

REM Convert N seconds to HH:MM:SS format
Function SecToHMS(inSec)
Dim workTime,secFrac,ss,mm,hh,timestring
workTime = Int(inSec)
ss = workTime MOD 60
workTime = (workTime - ss) / 60
mm = workTime MOD 60
hh = (workTime - mm) / 60
REM Format the time string
timestring = CStr(hh) + ":"
If mm < 10 Then
timestring = timestring + "0"
End If
timestring = timestring + CStr(mm) + ":"
If ss < 10 Then
timestring = timestring + "0"
End If
timestring = timestring + CStr(ss)
SecToHMS = timestring
End Function

REM -----------------------------------
REM Expand the functions supported
Expand Down
4 changes: 2 additions & 2 deletions test/Eval_Test.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off
REM "Multi" is a thread-pool emulation helper library for controlling multi-threaded windows batch [*.BAT] files
REM Copyright (c) 2020-2022 Adisak Pochanayon
REM "EvalBat" is a helper that lets you evaluate (vbscript) expressions in a batch file
REM Copyright (c) 2020-2023 Adisak Pochanayon
REM Contact: adisak@gmail.com
REM See EvalBat_License.txt for details
REM Currently hosted at https://github.com/adisak/EvalBat
Expand Down
72 changes: 72 additions & 0 deletions test/Time_Command.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@echo off
REM "EvalBat" is a helper that lets you evaluate (vbscript) expressions in a batch file
REM Copyright (c) 2020-2023 Adisak Pochanayon
REM Contact: adisak@gmail.com
REM See EvalBat_License.txt for details
REM Currently hosted at https://github.com/adisak/EvalBat

REM -----------------------------------

REM TEST script to Time a command
SETLOCAL
SET PATH=%PATH%;..\scripts

call :TestEBTimer

ENDLOCAL
goto:EOF

REM -----------------------------------
REM Subroutines
:BeginEBTimer
call EvalBat.bat Now
set %~1EBTimeBegin=%EVALBAT_RESULT%
goto:EOF

:EndEBTimer
call EvalBat.bat Now
set %~1EBTimeEnd=%EVALBAT_RESULT%
goto:EOF

:EvalEBTimer
SETLOCAL EnableDelayedExpansion
set TIMESTART=!%~1EBTimeBegin!
if "%~2"=="" (
set TIMEEND=!%~1EBTimeEnd!
) else (
set TIMEEND=!%~2EBTimeEnd!
)
ENDLOCAL & call EvalBat.bat DateDiff(''s'',cDate(''%TIMESTART%''),cDate(''%TIMEEND%''))
SETLOCAL
echo %EVALBAT_RESULT% seconds
call EvalBat.bat %EVALBAT_RESULT%/60
echo %EVALBAT_RESULT% minutes
ENDLOCAL
goto:EOF

REM -----------------------------------

:TestEBTimer
SETLOCAL

echo Time (10 seconds)

call :BeginEBTimer
timeout /T 10 /NOBREAK >NUL
call :EndEBTimer
call :EvalEBTimer

echo Time {T1} (5 seconds)

call :BeginEBTimer T1
timeout /T 5 /NOBREAK >NUL
call :EndEBTimer T1
call :EvalEBTimer T1

echo Total Time
call :EvalEBTimer "" T1

ENDLOCAL
goto:EOF

REM -----------------------------------

0 comments on commit 8427f00

Please sign in to comment.