mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 07:29:29 +02:00
* Correctly split date/time parts when dateseparator is a space
git-svn-id: trunk@13888 -
This commit is contained in:
parent
df5dec2106
commit
4c2fe8bc31
@ -633,51 +633,58 @@ end;
|
|||||||
|
|
||||||
function StrToDateTime(const s: string): TDateTime;
|
function StrToDateTime(const s: string): TDateTime;
|
||||||
var
|
var
|
||||||
i: integer;
|
I: integer;
|
||||||
begin
|
begin
|
||||||
i := Pos(' ',s);
|
I:=Pos(TimeSeparator,S);
|
||||||
if i > 0 then begin
|
If (I>0) then
|
||||||
result := ComposeDateTime(StrToDate(@S[1], i - 1, ShortDateFormat, DateSeparator)
|
begin
|
||||||
, StrToTime(@S[i+1], Length(S)-i , TimeSeparator));
|
While (I>0) and (S[I]<>' ') do
|
||||||
end
|
Dec(I);
|
||||||
else if pos(TimeSeparator,s) > 0 then
|
If I>0 then
|
||||||
result := StrToTime(s,TimeSeparator)
|
result:=ComposeDateTime(StrToDate(Copy(S,1,I-1)),StrToTime(Copy(S,i+1, Length(S)-i)))
|
||||||
else
|
else
|
||||||
result := StrToDate(s,LongDateFormat, DateSeparator)
|
result:=StrToTime(S)
|
||||||
end ;
|
end
|
||||||
|
else
|
||||||
function StrToDateTime(const s: ShortString; const UseFormat : TFormatSettings): TDateTime;
|
Result:=StrToDate(S);
|
||||||
var
|
|
||||||
i : integer;
|
|
||||||
begin
|
|
||||||
with useformat do begin
|
|
||||||
i := Pos(' ',s);
|
|
||||||
if i > 0 then begin
|
|
||||||
result := ComposeDateTime(StrToDate(@S[1], i - 1, ShortDateFormat, DateSeparator)
|
|
||||||
, StrToTime(@S[i+1], Length(S)-i , TimeSeparator));
|
|
||||||
end
|
|
||||||
else if pos(TimeSeparator,s) > 0 then
|
|
||||||
result := StrToTime(s,TimeSeparator)
|
|
||||||
else
|
|
||||||
result := StrToDate(s, ShortDateFormat, DateSeparator)
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function StrToDateTime(const s: AnsiString; const UseFormat : TFormatSettings): TDateTime;
|
function StrToDateTime(const s: AnsiString; const UseFormat : TFormatSettings): TDateTime;
|
||||||
var
|
var
|
||||||
i : integer;
|
I: integer;
|
||||||
begin
|
begin
|
||||||
with useformat do begin
|
I:=Pos(TimeSeparator,S);
|
||||||
i := Pos(' ',s);
|
If (I>0) then
|
||||||
if i > 0 then begin
|
begin
|
||||||
result := ComposeDateTime(StrToDate(@S[1], i - 1, ShortDateFormat, DateSeparator)
|
While (I>0) and (S[I]<>' ') do
|
||||||
, StrToTime(@S[i+1], Length(S)-i , TimeSeparator));
|
Dec(I);
|
||||||
end
|
If I>0 then
|
||||||
else if pos(TimeSeparator,s) > 0 then
|
result:=ComposeDateTime(StrToDate(Copy(S,1,I-1),UseFormat.ShortDateFormat,UseFormat.DateSeparator),
|
||||||
result := StrToTime(s,TimeSeparator)
|
StrToTime(Copy(S,i+1, Length(S)-i),UseFormat.TimeSeparator))
|
||||||
else
|
else
|
||||||
result := StrToDate(s,ShortDateFormat, DateSeparator)
|
result:=StrToTime(S,UseFormat.TimeSeparator)
|
||||||
end;
|
end
|
||||||
|
else
|
||||||
|
Result:=StrToDate(S,UseFormat.ShortDateFormat,UseFormat.DateSeparator);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function StrToDateTime(const s: ShortString; const UseFormat : TFormatSettings): TDateTime;
|
||||||
|
var
|
||||||
|
I: integer;
|
||||||
|
begin
|
||||||
|
I:=Pos(TimeSeparator,S);
|
||||||
|
If (I>0) then
|
||||||
|
begin
|
||||||
|
While (I>0) and (S[I]<>' ') do
|
||||||
|
Dec(I);
|
||||||
|
If I>0 then
|
||||||
|
result:=ComposeDateTime(StrToDate(Copy(S,1,I-1),UseFormat.ShortDateFormat,UseFormat.DateSeparator),
|
||||||
|
StrToTime(Copy(S,i+1, Length(S)-i),UseFormat.TimeSeparator))
|
||||||
|
else
|
||||||
|
result:=StrToTime(S,UseFormat.TimeSeparator)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result:=StrToDate(S,UseFormat.ShortDateFormat,UseFormat.DateSeparator);
|
||||||
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