' Function: jcdbl(string)
' Convert a string expression into a double number
Function jcdbl(str)
	jcdbl = cdbl(str)
End Function

' Function: jclng(string)
' COnvert a string expression into a long integer number
Function jclng(str)
	jlng = clng(str)
End Function

' Function: jcint(string)
' Convert a string expression into a integer number
Function jcint(str)
	jcint = cint(str)
End Function

' Function: trimtext(string)
' Cut all the space at the end and the begining of string
Function trimtext(str)
	trimtext = trim(str)
End Function

' Function: gHour(string)
' Get hour in the day string
' Disabled
Function gHour(str)
	if trim(str)="" then 
		gHour = 0
		exit function
	end if
	tSerial = TimeValue(str)
	gHour = Hour(tSerial)
	if (Minute(tSerial)>=53 and Minute(tSerial)<=59) then
		gHour = gHour + 1
	end if
End Function

' Function: gMinute(string)
' Get minute in the day string
' Disabled
Function gMinute(str)
	if trim(str)="" then
		gMInute = 0
		exit function
	end if
	Dim tSerial,h
	tSerial = TimeValue(str)
	h = Minute(tSerial)
	If (h>=0 And h<=7) OR (h>=53 and h<=59) then
		gMinute = 0
	ElseIf (h>=8 and h<=23) then
		gMinute = 15
	ElseIf (h>=24 and h<=38) then
		gMinute = 30
	ElseIf (h>=39 and h<=52) then
		gMinute = 45
	End If
End Function

' Function: isPast(dt)
' Return 0 if in the past time
Function isPast(dt)
	if trim(dt)="" then
		isPast = 0
		exit function
	end if
	if not isdate(dt) then
		isPast = 0
		exit function
	end if
	oetime = DateValue(dt)
	nstime = DateValue(now)
	'msgbox oetime & "-" & nstime & "-" & (oetime>nstime)
	if (oetime>nstime) then 
		isPast = 1
	else
		isPast = 0
	end if
End FUnction


' Function: isGreater(nst,oet)
' Return 0 if nst is greater than oet if nst and oet are a date formatted 
Function isGreater(nst,oet)
	if trim(nst)="" or trim(oet)="" then
		isGreater = 1
		exit function
	end if
	oetime = DateValue(oet)
	nstime = DateValue(nst)
	'msgbox oetime & "-" & nstime & "-" & (oetime>nstime)
	if (oetime>nstime) then 
		isGreater = 0
	else
		isGreater = 1
	end if
End FUnction

' Function: dateValidate(string)
' Return 1 if the input string is a date formatted, otherwise
Function dateValidate(str)
	'msgbox(str & "--" & cstr(instr(1,str,", 0")))
	if instr(1,str,", 0")>=1 OR instr(1,str,"/0")>=1  then
		dateValidate=0
		exit function
	end if
	if isdate(str) then
		dateValidate=1
	else
		dateValidate=0
	end if
End Function

'Check if input date is today
'
Function isToday(str)
	if (isdate(str)) then
		if cdate(str)=now() then
			isToday=true
		else
			isToday=false
		end if
	else
		isToday=false
	end if
End Function
