-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathGetTimeDifference.ahk
58 lines (40 loc) · 1.2 KB
/
GetTimeDifference.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
GetTimeDifference(fnStartTime,fnEndTime,fnTimeUnits := "Seconds")
{
; returns difference between two times in the specified units
; MsgBox fnStartTime %fnStartTime%`nfnEndTime %fnEndTime%`nfnTimeUnits %fnTimeUnits%
; declare local, global, static variables
Try
{
; set default return value
TimeDifference := "X"
; validate parameters
If fnTimeUnits not in Seconds,S,Minutes,M,Hours,H,Days,D
Throw, Exception("fnTimeUnits not in Seconds,S,Minutes,M,Hours,H,Days,D")
If !fnStartTime
fnStartTime := A_Now
If fnStartTime is not time
Throw, Exception("fnStartTime is not time")
If !fnEndTime
fnEndTime := A_Now
If fnEndTime is not time
Throw, Exception("fnEndTime is not time")
; initialise variables
; calculate time difference
TimeDifference := fnEndTime
EnvSub, TimeDifference, fnStartTime, %fnTimeUnits%
}
Catch, ThrownValue
{
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,0)
}
Finally
{
}
; return
Return TimeDifference
}
/* ; testing
TimeUnits := "seconds"
TimeDiff := GetTimeDifference("19000101120000","19000101115959",TimeUnits)
MsgBox, TimeDiff: %TimeDiff% %TimeUnits%
*/