Sign in to follow this  
Followers 0
Rogue5099

cycle times - DateDiff

5 posts in this topic

I'm having trouble with an algorithm.

There is 7 25 hour days in a cycle (7*25*60*60),

5 hour segments each cycle (5*60*60).

Very first start of this cycle is 2014/01/15 10:00:00 UTC

If I have GUICtrlCreateMonthCal and I select a day, I want to calculate when the cycle starts, ends and each segment within the cycle.

I'm EST so that's also a 5 hour difference from UTC.

All I have is the easy GUI and drawing a mind blank...

#include <GUIConstants.au3>
#include <Date.au3>

Global $UTC = "2014/01/15 10:00:00"

$GUI = GUICreate("Cycles", 499, 437, 193, 126)
$Calander = GUICtrlCreateMonthCal(_NowCalc(), 16, 96, 226, 161)
GUICtrlCreateGroup("Current Cycle", 16, 264, 225, 137)
GUICtrlCreateLabel("Cycle Start:", 48, 296, 58, 17)
GUICtrlCreateLabel("Next Checkpoint:", 24, 328, 86, 17)
GUICtrlCreateLabel("Cycle End:", 48, 360, 55, 17)
$CurrentCycle = GUICtrlCreateInput("", 112, 296, 113, 21, 0x0801)
$CurrentCycleStart = GUICtrlCreateInput("", 112, 328, 113, 21, 0x0801)
$CurrentCycleEnd = GUICtrlCreateInput("", 112, 360, 113, 21, 0x0801)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Predicted Cycle", 256, 80, 225, 321)
GUICtrlCreateLabel("Cycle Start:", 264, 112, 58, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 144, 61, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 176, 61, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 208, 61, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 240, 61, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 272, 61, 17)
GUICtrlCreateLabel("Cycle End:", 264, 304, 55, 17)
$CycleStart = GUICtrlCreateInput("", 336, 112, 121, 21, 0x0801)
$Checkpoint1 = GUICtrlCreateInput("", 336, 144, 121, 21, 0x0801)
$Checkpoint2 = GUICtrlCreateInput("", 336, 176, 121, 21, 0x0801)
$Checkpoint3 = GUICtrlCreateInput("", 336, 208, 121, 21, 0x0801)
$Checkpoint4 = GUICtrlCreateInput("", 336, 240, 121, 21, 0x0801)
$Checkpoint5 = GUICtrlCreateInput("", 336, 272, 121, 21, 0x0801)
$CycleEnd = GUICtrlCreateInput("", 336, 304, 121, 21, 0x0801)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    If $msg = $Calander Then _Update(GUICtrlRead($Calander))
Until $msg = $GUI_EVENT_CLOSE

Func _Update($Date)
    MsgBox(0, "", $Date)
EndFunc

Share this post


Link to post
Share on other sites



Hours appear to be the smallest units necessary for all calculations.

However, as only a date is selected to find the current cycle, I picked 12 noon as a default selected time to go with the selected date.

#include <GUIConstants.au3>
#include <Date.au3>

Global $UTC = "2014/01/15 10:00:00"

$GUI = GUICreate("Cycles", 499, 437, 193, 126)
$Calander = GUICtrlCreateMonthCal(_NowCalc(), 16, 96, 226, 161)
GUICtrlCreateGroup("Current Cycle", 16, 264, 225, 137)
GUICtrlCreateLabel("Cycle Start:", 48, 296, 58, 17)
GUICtrlCreateLabel("Next Checkpoint:", 24, 328, 86, 17)
GUICtrlCreateLabel("Cycle End:", 48, 360, 55, 17)
$CurrentCycle = GUICtrlCreateInput("", 112, 296, 113, 21, 0x0801)
$CurrentCycleStart = GUICtrlCreateInput("", 112, 328, 113, 21, 0x0801)
$CurrentCycleEnd = GUICtrlCreateInput("", 112, 360, 113, 21, 0x0801)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Predicted Cycle", 256, 80, 225, 321)
GUICtrlCreateLabel("Cycle Start:", 264, 112, 58, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 144, 61, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 176, 61, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 208, 61, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 240, 61, 17)
GUICtrlCreateLabel("Checkpoint:", 264, 272, 61, 17)
GUICtrlCreateLabel("Cycle End:", 264, 304, 55, 17)
$CycleStart = GUICtrlCreateInput("", 336, 112, 121, 21, 0x0801)
$Checkpoint1 = GUICtrlCreateInput("", 336, 144, 121, 21, 0x0801)
$Checkpoint2 = GUICtrlCreateInput("", 336, 176, 121, 21, 0x0801)
$Checkpoint3 = GUICtrlCreateInput("", 336, 208, 121, 21, 0x0801)
$Checkpoint4 = GUICtrlCreateInput("", 336, 240, 121, 21, 0x0801)
$Checkpoint5 = GUICtrlCreateInput("", 336, 272, 121, 21, 0x0801)
$CycleEnd = GUICtrlCreateInput("", 336, 304, 121, 21, 0x0801)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    If $msg = $Calander Then _Update(GUICtrlRead($Calander))
Until $msg = $GUI_EVENT_CLOSE

Func _Update($Date)
    Local $sText
    $dDiff = Mod(_DateDiff("h", $UTC, $Date & " 12:00:00"), (7 * 25)) ; Number of hours that $Date @ noon is into its current 7 day, (25hr per day) cycle.
    $StartCycle = _DateAdd("h", -(Mod(_DateDiff("h", $UTC, $Date & " 10:00:00"), (7 * 25))), $Date & " 10:00:00")
    $sText = "StartCycle  = " & $StartCycle & " UTC time" & @LF
    For $i = 1 To Int(7 * 25 / 5) ; Check every 5 Hrs for a 7*25 hrs cycle Starting at $StartCycle (date/time).
        $sText &= "End of " & $i & ", 5 hr segment = " & _DateAdd("h", $i * 5, $StartCycle) & " UTC time" & @LF
    Next
    MsgBox(0, "", $sText)
EndFunc   ;==>_Update

Share this post


Link to post
Share on other sites

@Malkey - could you use something like this from the help file to get the UTC time when the user clicks a date instead of the noon plug?

$tLocal = _Date_Time_GetLocalTime()
$tSystem = _Date_Time_TzSpecificLocalTimeToSystemTime(DllStructGetPtr($tLocal))
MemoWrite("Local time to system time .: " & _Date_Time_SystemTimeToDateTimeStr($tSystem))

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

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
Sign in to follow this  
Followers 0