#include-once
; #INDEX# =======================================================================================================================
; Title .........: TimeMin
; AutoIt Version: 3.2.3++
; Language:       English
; Description:    Functions that assist with Time calculation.
; ===============================================================================================================================
; ------------------------------------------------------------------------------
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Time management.
; ------------------------------------------------------------------------------

; #FUNCTION# ====================================================================================================================
; Name...........: _TimetoMin()
; Description ...: Change the format from Time to Minutes like: 08:45 --> 525
; Syntax.........: _TimetoMin($msg)
; Parameters ....: $msg     	 	   - Time to convert in format "(+/-)05:04" Returns(+/-) only if it comes with $msg!
; Return values .: Success   		   - Time in minutes with "+/-mmmmm" 
;                  Failure: @error     - 1 = Function called with wrong Parameter (not in format (+/-)hhhh:mm)
;                  Failure: @error     - 2 = Function called with wrong Parameter (hhhh/mm are no Digits)
;                  Failure: @error     - 3 = Function called with wrong Parameter (mm > 59)
; Author ........: Oliver Zimmermann 	<o_z at gmx dot net> (Schnuffel)
; Modified.......:
; Remarks .......: 
; Related .......: _MintoTime()
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _TimetoMin($msg)
	Local $vz="", $Mins1, $Mins2, $sumtoMin
	If  StringLeft($msg,1)="+" Then
		$vz="+"
		$msg=StringTrimLeft($msg,1)
	ElseIf StringLeft($msg,1)="-" Then
		$vz="-"
		$msg=StringTrimLeft($msg,1)
	EndIf
	$msg=StringSplit($msg,":")
	If @error=1 Then 
		setError(1)
		Return 0
	EndIf
	If StringIsDigit($msg[1])=0 Or StringIsDigit($msg[2])=0 Then 
		setError(2)
		Return 0
	EndIf		
	If $msg[2]>59 Then
		setError(3)
		Return 0
	EndIf
	$msg[1]=$msg[1]*60
	$sumtoMin=$msg[1]+$msg[2]
	$msg=0
	setError(0)
	Return($vz&$sumtoMin)
EndFunc
; #FUNCTION# ====================================================================================================================
; Name...........: _MintoTime()
; Description ...: Change the format from minutes to Time format like: 08:45 --> +525
; Syntax.........: _MintoTime($msg)
; Parameters ....: $msg     	 	   - Minutes to convert in format "+/-mmmmmm" Returns(+/-) only if it comes with $msg!
; Return values .: Success   		   - Time in format "+/-hh:mm"
;                  Failure: @error     - 1 = Function called with wrong Parameter (not in format (+/-)mmmmm; 'mmmm' are no Digits)
; Author ........: Oliver Zimmermann 	<o_z at gmx dot net> (Schnuffel)
; Modified.......:
; Remarks .......:
; Related .......: _TimetoMin()
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _MintoTime($msg)
	Local $Hours, $Mins, $vz=""
	If  StringLeft($msg,1)="+" Then
		$msg=StringTrimLeft($msg,1)
		$vz="+"	
	ElseIf StringLeft($msg,1)="-" Then
		$vz="-"
		$msg=StringTrimLeft($msg,1)
	EndIf	
	If StringIsDigit($msg)=0 Then
		SetError(1)
		Return(0)
	EndIf
	$Hours=StringSplit($msg/60,".")
	$Mins=$msg-($Hours[1]*60)
	If $Mins<10 Then $Mins="0"&$Mins
	If $Hours[1]<10 Then $Hours[1]="0"&$Hours[1]	
	$msg=0
	setError(0)
	Return ($vz&$Hours[1]&":"&$Mins)
EndFunc