mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 18:30:18 +02:00
* Patch from Joao Morais to fix the case where only a time is provided
git-svn-id: trunk@11199 -
This commit is contained in:
parent
3df8e7ae7b
commit
767e3fee62
@ -516,15 +516,37 @@ begin
|
|||||||
end ;
|
end ;
|
||||||
|
|
||||||
{ StrToDateTime converts the string S to a TDateTime value
|
{ StrToDateTime converts the string S to a TDateTime value
|
||||||
if S does not represent a valid date and time value
|
if S does not represent a valid date and/or time value
|
||||||
an EConvertError will be raised }
|
an EConvertError will be raised }
|
||||||
|
|
||||||
function StrToDateTime(const s: string): TDateTime;
|
function StrToDateTime(const s: string): TDateTime;
|
||||||
var i: integer;
|
var
|
||||||
|
i, j, k, l: integer;
|
||||||
|
sd, st: string;
|
||||||
begin
|
begin
|
||||||
i := pos(' ', s);
|
l := Length(s);
|
||||||
if i > 0 then result := ComposeDateTime(StrToDate(Copy(S, 1, i - 1)), StrToTime(Copy(S, i + 1, length(S))))
|
i := 1;
|
||||||
else result := StrToDate(S);
|
while (i <= l) and (s[i] = ' ') do
|
||||||
|
Inc(i);
|
||||||
|
j := i;
|
||||||
|
while (j <= l) and (s[j] <> ' ') do
|
||||||
|
Inc(j);
|
||||||
|
k := j;
|
||||||
|
while (k <= l) and (s[k] = ' ') do
|
||||||
|
Inc(k);
|
||||||
|
sd := Copy(s, i, j - i);
|
||||||
|
st := Copy(s, k, l);
|
||||||
|
if (st = '') and (Pos(TimeSeparator, sd) > 0) then
|
||||||
|
begin
|
||||||
|
st := sd;
|
||||||
|
sd := '';
|
||||||
|
end;
|
||||||
|
if (sd <> '') and (st <> '') then
|
||||||
|
Result := ComposeDateTime(StrToDate(sd), StrToTime(st))
|
||||||
|
else if st = '' then
|
||||||
|
Result := StrToDate(sd)
|
||||||
|
else
|
||||||
|
Result := StrToTime(st);
|
||||||
end ;
|
end ;
|
||||||
|
|
||||||
{ FormatDateTime formats DateTime to the given format string FormatStr }
|
{ FormatDateTime formats DateTime to the given format string FormatStr }
|
||||||
|
Loading…
Reference in New Issue
Block a user