Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :timeSince Time [Date [part whole]]
- :: input - hh:mm:ss.cc [Day MM/DD/YYYY [intPart intWhole]]
- :: output - [[[[#wks, ]#day, ]#hrs, ]#min, ]#.#sec
- :: Returns time lapsed from %TIME% [%DATE%] to present in %TS_% and if given
- :: part+whole will return estimate of time remaining to completion in %TR_%.
- :: Raw time and day info for given(1) and current(2) are also available.
- :: TM1,TM2=# of centiseconds since last midnight.
- :: DY1,DY2=# of days since noon on January 1, 4713 BCE (Julian calendar).
- :: usage:
- :: SET "startTime=%TIME%" or "startTime=%TIME% %DATE%" before event then:
- :: CALL :timeSince %startTime% - for current elapsed time.
- :: CALL :timeSince %startTime% %partCnt% %wholeCnt% - to estimate by count.
- :: CALL :timeSince %startTime% %partKb% %wholeKb% - to estimate by size.
- :: v0.3 2020/07/29
- ::
- SETLOCAL EnableDelayedExpansion
- SET inp=%*
- SET/A p=t=t1=tm1=t2=tm2=d=d1=dy1=d2=dy2=x=y=z=0
- IF "!inp:~1,1!"==":" SET inp=0!inp!
- FOR %%@ IN ("!inp!" "!TIME: =0! !DATE!") DO (SET/A p+=1
- FOR /F "tokens=1-10 delims=:./ " %%A IN ("%%~@")DO IF "%%D" NEQ "" (
- SET/A"tm!p!=t!p!=(((1%%A*60)+1%%B)*60+1%%C)*100+1%%D-36610100"
- IF "%%H" NEQ "" (SET/A mm=100%%F%%100,dd=100%%G%%100,yy=10000%%H%%10000
- SET/A"dy!p!=d!p!=!dd!-32075+1461*(!yy!+4800+(!mm!-14)/12)/4+367*(!mm!-2-(!mm!-14)/12*12)/12-3*((!yy!+4900+(!mm!-14)/12)/100)/4"
- IF "%%J" NEQ "" (SET y=%%I)&(SET z=%%J))))
- IF !t1! GEQ !t2! SET/A t2+=8640000,d2-=1
- IF !d2! LSS !d1! SET/A d2=d1
- IF !d1! EQU 0 SET d2=0
- SET/A t1=t2-t1,d1=d2-d1,d2=t2=0
- IF !z! NEQ 0 (
- SET xx=0000000009999999
- SET yy=000000000000000!y!
- SET zz=000000000000000!z!
- IF "!yy:~-16!" GTR "!zz:~-16!" SET y=!z!
- FOR /L %%A IN (1,1,8) DO IF "!zz:~-16!" GTR "!xx:~-16!" SET "xx=!xx!9" & SET x=%%A
- IF !x! NEQ 0 FOR %%A IN (!x!) DO SET "y=!y:~0,-%%A!" & SET "z=!z:~0,-%%A!"
- IF "!y!"=="" SET y=1
- IF !y! LSS 1 SET y=1
- SET/A"t2=(z-y)*100/y*((d1*8640000+t1)/100),d2=t2/8640000,t2=t2%%8640000")
- FOR %%A IN (1 2) DO ( SET res=
- SET/A"d=d%%A,t=t%%A,w=d/7,d=d%%7,h=t%%8640000/360000,m=t%%360000/6000,s=t%%6000/100,c=t%%100"
- IF !c! LEQ 9 SET c=0!c!
- IF !w! GTR 0 SET "res=!w!wks, "
- IF !d! GTR 0 SET "res=!res!!d!day, "
- IF !h! GTR 0 SET "res=!res!!h!hrs, "
- IF !m! GTR 0 SET "res=!res!!m!min, "
- SET r%%A=!res!!s!.!c!sec)
- ( ENDLOCAL
- SET "TS_=%r1%"
- SET "TR_=%r2%"
- REM SET "tm1=%tm1%"
- REM SET "tm2=%tm2%"
- REM SET "dy1=%dy1%"
- REM SET "dy2=%dy2%"
- )
- EXIT /B 0
Advertisement