Browse Source

* Correctly split date/time parts when dateseparator is a space

git-svn-id: trunk@13888 -
michael 16 years ago
parent
commit
4c2fe8bc31
1 changed files with 47 additions and 40 deletions
  1. 47 40
      rtl/objpas/sysutils/dati.inc

+ 47 - 40
rtl/objpas/sysutils/dati.inc

@@ -633,51 +633,58 @@ end;
 
 function StrToDateTime(const s: string): TDateTime;
 var
-  i: integer;
-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,LongDateFormat, DateSeparator)
-end ;
+  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)),StrToTime(Copy(S,i+1, Length(S)-i)))
+    else
+      result:=StrToTime(S)
+    end
+  else
+    Result:=StrToDate(S);
+end;
 
-function StrToDateTime(const s: ShortString; const UseFormat : TFormatSettings): TDateTime;
+function StrToDateTime(const s: AnsiString; const UseFormat : TFormatSettings): TDateTime;
 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;
+  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;
 
-function StrToDateTime(const s: AnsiString; const UseFormat : TFormatSettings): TDateTime;
+function StrToDateTime(const s: ShortString; const UseFormat : TFormatSettings): TDateTime;
 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;
+  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;
 
 {   FormatDateTime formats DateTime to the given format string FormatStr   }