Browse Source

+ TryStrToDate/Time functions

florian 20 years ago
parent
commit
bf179526ff
2 changed files with 60 additions and 2 deletions
  1. 50 1
      rtl/objpas/sysutils/dati.inc
  2. 10 1
      rtl/objpas/sysutils/datih.inc

+ 50 - 1
rtl/objpas/sysutils/dati.inc

@@ -753,9 +753,58 @@ begin
           EncodeTime(Time shr 11, (Time shr 5) and 63, (Time and 31) shl 1,0);
 end;
 
+
+function TryStrToDate(const S: string; out Value: TDateTime): Boolean;
+  begin
+    result:=true;
+    try
+      value:=StrToDate(s);
+    except
+      on EConvertError do
+        result:=false
+    end;
+  end;
+  
+  
+// function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
+
+
+function TryStrToTime(const S: string; out Value: TDateTime): Boolean;
+  begin
+    result:=true;
+    try
+      value:=StrToTime(s);
+    except
+      on EConvertError do
+        result:=false
+    end;
+  end;
+  
+  
+// function TryStrToTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
+
+
+function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
+  begin
+    result:=true;
+    try
+      value:=StrToDateTime(s);
+    except
+      on EConvertError do
+        result:=false
+    end;
+  end;
+  
+  
+// function TryStrToDateTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
+
+
 {
   $Log$
-  Revision 1.9  2005-03-25 22:53:39  jonas
+  Revision 1.10  2005-05-07 10:23:17  florian
+    + TryStrToDate/Time functions
+
+  Revision 1.9  2005/03/25 22:53:39  jonas
     * fixed several warnings and notes about unused variables (mainly) or
       uninitialised use of variables/function results (a few)
 

+ 10 - 1
rtl/objpas/sysutils/datih.inc

@@ -122,13 +122,22 @@ function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
 procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
 Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
 Function FileDateToDateTime (Filedate : Longint) :TDateTime;
+function TryStrToDate(const S: string; out Value: TDateTime): Boolean;
+// function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
+function TryStrToTime(const S: string; out Value: TDateTime): Boolean;
+// function TryStrToTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
+function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
+// function TryStrToDateTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
 
 { FPC Extra }
 Procedure GetLocalTime(var SystemTime: TSystemTime);
 
 {
   $Log$
-  Revision 1.4  2005-03-17 15:21:10  marco
+  Revision 1.5  2005-05-07 10:23:17  florian
+    + TryStrToDate/Time functions
+
+  Revision 1.4  2005/03/17 15:21:10  marco
    * fixed incmonths default param. Thnks nldelphi
 
   Revision 1.3  2005/02/14 17:13:31  peter