function Str2Time (const TimeStr: string): TDateTime;
var
S: string;
begin
S := Trim (TimeStr);
if S = '' then
begin
Result := 0.0;
Exit;
end;
if IsDigitStr (S) then
begin
case Length (S) of
4: S := LeftStr (S, 2) + TimeSeparator + RightStr (S, 2);
6: S := LeftStr (S, 2) + TimeSeparator + Copy (S, 3, 2)
+ TimeSeparator + Copy (S, 5, 2);
end;
end;
try
// Allow '.' and ':' as valid alternatives for TimeSeparator
S := ReplaceChStr (S, '.', TimeSeparator);
S := ReplaceChStr (S, ':', TimeSeparator);
// S := ReplaceChStr ( S, ' ', TimeSeparator);
// Remove trailing Separator if any
if S [Length (S)] = TimeSeparator then
begin
S := LeftStr (S, Length (S) - 1);
if S = '' then
begin
Result := 0.0;
Exit;
end;
end;
//Frac ensures the Date Component is 0
Result := Frac (StrToTime (S));
except
Result := 0.0;
if ESBRaiseDateError then
raise;
end;
End; |