' ---------------------------------------------------------------------
' Formatting dates
' ---------------------------------------------------------------------
Function FormatShortTime(value)
	IF (value <> "") THEN
		FormatShortTime = FormatDateTime(value, vbShortTime)
	ELSE
		FormatShortTime = ""
	END IF
End Function

Function FormatLongTime(value)
	IF (value <> "") THEN
		FormatLongTime = FormatDateTime(value, vbLongTime)
	ELSE
		FormatLongTime = ""
	END IF
End Function

Function FormatShortDate(value)
	IF (value <> "") THEN
		FormatShortDate = FormatDateTime(value, vbShortDate)
	ELSE
		FormatShortDate = ""
	END IF
End Function

Function FormatLongDate(value)
	IF (value <> "") THEN
		FormatLongDate = FormatDateTime(value, vbLongDate)
	ELSE
		FormatLongDate = ""
	END IF
End Function

Function GetDate()
	GetDate = Date()
End Function

Function DateAddDays(dt, days)
	DateAddDays = DateAdd("D", days, dt)
End Function

Function CompareDates(dt1, dt2)
	If CDate(dt1) > CDate(dt2) Then
		CompareDates = 1
	Else
		If CDate(dt1) < CDate(dt2) Then
			CompareDates = -1
		Else
			CompareDates = 0
		End if
	End if
End Function
' ---------------------------------------------------------------------
' Formatting numbers
' ---------------------------------------------------------------------
Function FormatPercent(value)
	IF (value <> "") THEN
		FormatPercent = FormatNumber(value, 2, true, true, true) + "%"
	ELSE
		FormatPercent = ""
	END IF
End Function

Function FormatPercentWithDecimals(value)
	sNumber = FormatNumber(value, 4)
	i = Len(sNumber)

	While (i > 0 AND Mid(sNumber, i, 1) = "0")
		sNumber = Left(sNumber, Len(sNumber) - 1)
		i = i - 1
	Wend

	IF (Instr(sNumber, ".") > 0) THEN
		decimals = (Len(sNumber) - Instr(sNumber, "."))
	END IF

	IF (Instr(sNumber, ",") > 0) THEN
		decimals = (Len(sNumber) - Instr(sNumber, ","))
	END IF

	IF (decimals < 2) THEN
		sNumber = sNumber + String(2 - decimals, "0")
	END IF
	
	FormatPercentWithDecimals = sNumber + "%"
End Function

Function FormatCurrency(value)
	Dim result
	
	IF (value <> "") THEN
		result = "$" + FormatNumber(value, 2, true, true, true)
	ELSE
		result = ""
	END IF
	
	result = replace(result, "$(", "($")
	
	FormatCurrency = result
End Function

Function GetNumberFromString(value)
	dim result
	
	result = value

	result = replace(result, "$", "")
	result = replace(result, "%", "")
	result = replace(result, "(", "-")
	result = replace(result, ")", "")
	result = replace(result, ")", "")

	IF IsNumeric(result) Then
		GetNumberFromString = CDbl(result)
	ELSE
		GetNumberFromString = 0
	END IF
End Function

Function IsValidNumber(value)
	dim result
	
	result = value

	result = replace(result, "$", "")
	result = replace(result, "%", "")
	result = replace(result, "(", "-")
	result = replace(result, ")", "")
	result = replace(result, ")", "")
	
	IsValidNumber = IsNumeric(result)
End Function
