为什么_DateDiff()返回0?

时间:2018-01-08 19:59:51

标签: date time autoit time-estimation

我的AutoIt脚本应该通过说The process will be complete at 3:18:24 PM来预测进程何时完成。但那并没有发生。它需要以下输入值:

  1. 开始时间
  2. 起始百分比
  3. 当前时间
  4. 当前百分比
  5. 显示:

    "The extraction will be complete at 0".
    

    我将问题隔离到_DateDiff()。我认为第一个参数是n,以分钟为单位。但是当我传递接下来的两个参数(相隔六十分钟的日期值)时,它会返回0。这是代码:

    GUICreate("Completion Time Predictor", 300, 300)
    ;Here I enter the starting time and percentage
    GUICtrlCreateLabel("Enter the start time:", 10, 10, 270, 29)
    $StartTime = GUICtrlCreateDate("", 10, 40, 270, 21, $DTS_TIMEFORMAT)
    GUICtrlCreateLabel("Enter the start percentage:", 10, 70, 270, 29)
    Local $StartPercent = GUICtrlCreateInput("", 10, 100, 270, 21)
    ;Here I enter the current time and percentage
    GUICtrlCreateLabel("Enter the current time:", 10, 130, 270, 29)
    $CurrentTime = GUICtrlCreateDate("", 10, 160, 270, 21, $DTS_TIMEFORMAT)
    GUICtrlCreateLabel("Enter the current percentage:", 10, 190, 270, 29)
    Local $CurrentPercent = GUICtrlCreateInput("", 10, 220, 270, 21)
    Local $CTRL_a = GUICtrlCreateButton("Calculate", 10, 260, 280, 21)
    GUISetState()
    Local $msg
    Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $CTRL_a
                $PercentChange = GUICtrlRead($CurrentPercent) - GUICtrlRead($StartPercent)
                ;This seems to be where everything is going wrong
                $ChangePerMinute = $PercentChange / _DateDiff('n', GUICtrlRead($StartTime), GUICtrlRead($CurrentTime))
                $MinutesRemaining = (100 - GUICtrlRead($CurrentPercent)) / $ChangePerMinute
                $EndTime = _DateAdd('n', $MinutesRemaining, GUICtrlRead($CurrentTime))
                MsgBox($MB_OK, "Predicted Completion Time:", "The extraction will be complete at  " & $EndTime)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
    

1 个答案:

答案 0 :(得分:0)

我不知道你在做什么,但也许这有助于你找到问题

#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
GUICreate("Completion Time Predictor", 300, 300)
;Here I enter the starting time and percentage
GUICtrlCreateLabel("Enter the start time:", 10, 10, 270, 29)
$StartTime = GUICtrlCreateDate("", 10, 40, 270, 21, $DTS_TIMEFORMAT)
GUICtrlCreateLabel("Enter the start percentage:", 10, 70, 270, 29)
Local $StartPercent = GUICtrlCreateInput("0", 10, 100, 270, 21)
;Here I enter the current time and percentage
GUICtrlCreateLabel("Enter the current time:", 10, 130, 270, 29)
$CurrentTime = GUICtrlCreateDate("", 10, 160, 270, 21, $DTS_TIMEFORMAT)
GUICtrlSetData(-1, _NowCalcDate() & ' ' & @HOUR + 1 & ":" & @MIN & ':' & @SEC)
GUICtrlCreateLabel("Enter the current percentage:", 10, 190, 270, 29)
Local $CurrentPercent = GUICtrlCreateInput("10", 10, 220, 270, 21)
Local $CTRL_a = GUICtrlCreateButton("Calculate", 10, 260, 280, 21)
GUISetState()
Local $msg

Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $CTRL_a
            ConsoleWrite(_NowCalcDate() & ' ' & GUICtrlRead($StartTime) & " " & _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime) & @CRLF)
            $PercentChange = GUICtrlRead($CurrentPercent) - GUICtrlRead($StartPercent)
            ConsoleWrite("% Change: " & $PercentChange & @CRLF)
            ;This seems to be where everything is going wrong
            $diff_min = _DateDiff('n', _NowCalcDate() & ' ' & GUICtrlRead($StartTime), _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime))
            ConsoleWrite("Diff in Min: " & $diff_min & @CRLF)
            $ChangePerMinute = $PercentChange / $diff_min
            ConsoleWrite("Change / min : " & $ChangePerMinute & @CRLF)
            $MinutesRemaining = (100 - GUICtrlRead($CurrentPercent)) / $ChangePerMinute
            ConsoleWrite("MinutesRemaining : " & " " & $MinutesRemaining & @CRLF)
            $EndTime = _DateAdd('n', $MinutesRemaining, _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime))
            MsgBox($MB_OK, "Predicted Completion Time:", "The extraction will be complete at  " & $EndTime)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE