Jump to content
topten

Time counting issue

Recommended Posts

topten

Which is the best algo of time counting?

For example I get innitial time of counting @HOUR @MIN . Say I have 17:45. For some time the script will need to sleep for X minutes and then continue on its work. Say I have 120 minutes of sleep or 210 minutes of sleep. Which is the best algo of calculating the time of script to continue?

 

Great thanx in advance!

Share this post


Link to post
Share on other sites
Jewtus

Have you tried TimerDiff inside a do until statement?

EX

Do
sleep(10)
until TimerDiff($hTimer) > $timedelay

Share this post


Link to post
Share on other sites
topten

Ah, so nice! I didnt think of that! Thanx again!

Share this post


Link to post
Share on other sites
johnmcloud

Or:

; Johnmcloud

_Wait(@HOUR, @MIN + 1) ; wait 1 minute
;_Wait(@HOUR + 2, @MIN) ; wait 2 hour = 120 minutes

Func _Wait($iHour, $iMin)
    Do
        Sleep(1000)
        If @HOUR = $iHour And @MIN = $iMin Then ExitLoop
    Until 0
EndFunc   ;==>_Wait
Edited by johnmcloud

Share this post


Link to post
Share on other sites
czardas

LOL, I calculated the new time. Here's the code anyway.

;

Local $sNewTime = TimeInterval("17:45", "09:16")
MsgBox(0, "", $sNewTime)

Func TimeInterval($sCurrentTime, $sInterval)
    Local $aHH_MM = StringSplit($sCurrentTime, ":"), $aTimeAdd = StringSplit($sInterval, ":")
    If Not (IsArray($aHH_MM) And IsArray($aTimeAdd)) Then Return SetError(1)
    If $aHH_MM[0] <> 2 Or $aTimeAdd[0] <> 2 Then Return SetError(2)

    Local $iHours = $aHH_MM[1] + $aTimeAdd[1], $iMins = $aHH_MM[2] + $aTimeAdd[2]
    If $iMins > 59 Then $iHours += 1
    $iHours = Mod($iHours, 24)
    $iMins = Mod($iMins, 60)

    Return StringFormat("%02i:%02i", $iHours, $iMins)
EndFunc
Edited by czardas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.