Browse Source

* fixed encode/decode date/time

peter 26 years ago
parent
commit
190df10130
1 changed files with 17 additions and 23 deletions
  1. 17 23
      rtl/objpas/dati.inc

+ 17 - 23
rtl/objpas/dati.inc

@@ -31,14 +31,15 @@ const
        (0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335));
        (0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335));
 
 
 function DoEncodeDate(Year, Month, Day: Word): longint;
 function DoEncodeDate(Year, Month, Day: Word): longint;
-var c, ya: word;
+var
+  c, ya: cardinal;
 begin
 begin
-if (Month > 0) and (Month < 13) and (Day > 0) and (Day < 32) then 
+if (Month > 0) and (Month < 13) and (Day > 0) and (Day < 32) then
    begin
    begin
-     if month > 2 then Month := Month - 3 else 
+     if month > 2 then Month := Month - 3 else
      begin
      begin
        Month := Month + 9;
        Month := Month + 9;
-       Year:= Year - 1; 
+       Year:= Year - 1;
      end;
      end;
      c:= Year DIV 100;
      c:= Year DIV 100;
      ya:= Year - 100*c;
      ya:= Year - 100*c;
@@ -118,7 +119,7 @@ end ;
 
 
 procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
 procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
 var
 var
-  j: word;
+  j : cardinal;
 begin
 begin
   j := pred((Trunc(System.Int(Date)) + 693901) SHL 2);
   j := pred((Trunc(System.Int(Date)) + 693901) SHL 2);
   Year:= j DIV 146097;
   Year:= j DIV 146097;
@@ -139,9 +140,8 @@ end ;
     Hour, Minute, Second and MilliSecond    }
     Hour, Minute, Second and MilliSecond    }
 
 
 procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
 procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
-
-Var l : longint;
-
+Var
+  l : cardinal;
 begin
 begin
  l := Trunc(Frac(time) * MSecsPerDay);
  l := Trunc(Frac(time) * MSecsPerDay);
  Hour   := l div 3600000;
  Hour   := l div 3600000;
@@ -151,23 +151,14 @@ begin
  Second := l div 1000;
  Second := l div 1000;
  l := l mod 1000;
  l := l mod 1000;
  MilliSecond := l;
  MilliSecond := l;
-{
-  Time := Frac(Time) * 24;
-  Hour := Trunc(Time);
-  Time := Frac(Time) * 60;
-  Minute  := Trunc(Time);
-  Time := Frac(Time) * 60;
-  Second  := Trunc(Time);
-  MilliSecond := Trunc(Frac(Time) * 1000);
-  }
 end;
 end;
 
 
 {   DateTimeToSystemTime converts DateTime value to SystemTime   }
 {   DateTimeToSystemTime converts DateTime value to SystemTime   }
 
 
 procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
 procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
 begin
 begin
-DecodeDate(DateTime, SystemTime.Year, SystemTime.Month, SystemTime.Day);
-DecodeTime(DateTime, SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.MilliSecond);
+  DecodeDate(DateTime, SystemTime.Year, SystemTime.Month, SystemTime.Day);
+  DecodeTime(DateTime, SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.MilliSecond);
 end ;
 end ;
 
 
 {   SystemTimeToDateTime converts SystemTime to a TDateTime value   }
 {   SystemTimeToDateTime converts SystemTime to a TDateTime value   }
@@ -461,15 +452,15 @@ var
       end ;
       end ;
    StoreStr(pchar(@S[1]), Len);
    StoreStr(pchar(@S[1]), Len);
    end ;
    end ;
-   
+
    Function TimeReFormat(Const S : string) : string;
    Function TimeReFormat(Const S : string) : string;
    // Change m into n for time formatting.
    // Change m into n for time formatting.
    Var i : longint;
    Var i : longint;
-   
+
    begin
    begin
      Result:=S;
      Result:=S;
      For I:=1 to Length(Result) do
      For I:=1 to Length(Result) do
-       If Result[i]='m' then 
+       If Result[i]='m' then
          result[i]:='n';
          result[i]:='n';
    end;
    end;
 
 
@@ -652,7 +643,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.14  1999-07-14 08:47:54  michael
+  Revision 1.15  1999-07-24 11:21:14  peter
+    * fixed encode/decode date/time
+
+  Revision 1.14  1999/07/14 08:47:54  michael
   * faster En/Decodedate routines from Frank Reichert
   * faster En/Decodedate routines from Frank Reichert
   * Fixed FormatDateTime with short/longtimeformat.
   * Fixed FormatDateTime with short/longtimeformat.