Browse Source

+ Several dateutil-fixes for dates before 1899/12/30

git-svn-id: trunk@3687 -
joost 19 years ago
parent
commit
35c5b75792
1 changed files with 17 additions and 12 deletions
  1. 17 12
      rtl/objpas/sysutils/dati.inc

+ 17 - 12
rtl/objpas/sysutils/dati.inc

@@ -43,6 +43,13 @@ begin
     Result:=0;
     Result:=0;
 end;
 end;
 
 
+function ComposeDateTime(Date,Time : TDateTime) : TDateTime;
+
+begin
+  if Date < 0 then Result := Date - Time
+  else Result := Date + Time;
+end;
+
 {==============================================================================}
 {==============================================================================}
 {   Public functions                                                           }
 {   Public functions                                                           }
 {==============================================================================}
 {==============================================================================}
@@ -59,8 +66,8 @@ end ;
 
 
 function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
 function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
 begin
 begin
-  result := (TimeStamp.Date - DateDelta) + (TimeStamp.Time / MSecsPerDay);
-end ;
+  Result := ComposeDateTime(TimeStamp.Date - DateDelta,TimeStamp.Time / MSecsPerDay)
+end;
 
 
 {   MSecsToTimeStamp   }
 {   MSecsToTimeStamp   }
 
 
@@ -210,8 +217,8 @@ end ;
 
 
 function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
 function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
 begin
 begin
-  result := DoEncodeDate(SystemTime.Year, SystemTime.Month, SystemTime.Day) +
-            DoEncodeTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.MilliSecond);
+  result := ComposeDateTime(DoEncodeDate(SystemTime.Year, SystemTime.Month, SystemTime.Day),
+                            DoEncodeTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.MilliSecond));
 end ;
 end ;
 
 
 {   DayOfWeek returns the Day of the week (sunday is day 1)  }
 {   DayOfWeek returns the Day of the week (sunday is day 1)  }
@@ -481,7 +488,7 @@ function StrToDateTime(const s: string): TDateTime;
 var i: integer;
 var i: integer;
 begin
 begin
 i := pos(' ', s);
 i := pos(' ', s);
-if i > 0 then result := StrToDate(Copy(S, 1, i - 1)) + StrToTime(Copy(S, i + 1, length(S)))
+if i > 0 then result := ComposeDateTime(StrToDate(Copy(S, 1, i - 1)), StrToTime(Copy(S, i + 1, length(S))))
 else result := StrToDate(S);
 else result := StrToDate(S);
 end ;
 end ;
 
 
@@ -697,9 +704,8 @@ var
    end ;
    end ;
 
 
 begin
 begin
-  DecodeDate(DateTime, Year, Month, Day);
+  DecodeDateFully(DateTime, Year, Month, Day, DayOfWeek);
   DecodeTime(DateTime, Hour, Minute, Second, MilliSecond);
   DecodeTime(DateTime, Hour, Minute, Second, MilliSecond);
-  DayOfWeek := SysUtils.DayOfWeek(DateTime);
   ResultLen := 0;
   ResultLen := 0;
   ResultCurrent := @ResultBuffer;
   ResultCurrent := @ResultBuffer;
   StoreFormat(FormatStr);
   StoreFormat(FormatStr);
@@ -721,17 +727,16 @@ Var YY,MM,DD,H,m,s,msec : Word;
 
 
 begin
 begin
   Decodedate (DateTime,YY,MM,DD);
   Decodedate (DateTime,YY,MM,DD);
+  DecodeTime (DateTime,h,m,s,msec);
 {$ifndef unix}
 {$ifndef unix}
   If (YY<1980) or (YY>2099) then
   If (YY<1980) or (YY>2099) then
     Result:=0
     Result:=0
   else
   else
     begin
     begin
-    DecodeTime (DateTime,h,m,s,msec);
     Result:=(s shr 1) or (m shl 5) or (h shl 11);
     Result:=(s shr 1) or (m shl 5) or (h shl 11);
     Result:=Result or DD shl 16 or (MM shl 21) or ((YY-1980) shl 25);
     Result:=Result or DD shl 16 or (MM shl 21) or ((YY-1980) shl 25);
     end;
     end;
 {$else unix}
 {$else unix}
-  Decodetime(DateTime,h,m,s,msec);
   Result:=LocalToEpoch(yy,mm,dd,h,m,s);
   Result:=LocalToEpoch(yy,mm,dd,h,m,s);
 {$endif unix}
 {$endif unix}
 end;
 end;
@@ -751,15 +756,15 @@ Var Date,Time : Word;
 begin
 begin
   Date:=FileDate shr 16;
   Date:=FileDate shr 16;
   Time:=FileDate and $ffff;
   Time:=FileDate and $ffff;
-  Result:=EncodeDate((Date shr 9) + 1980,(Date shr 5) and 15, Date and 31) +
-          EncodeTime(Time shr 11, (Time shr 5) and 63, (Time and 31) shl 1,0);
+  Result:=ComposeDate(EncodeDate((Date shr 9) + 1980,(Date shr 5) and 15, Date and 31),
+          EncodeTime(Time shr 11, (Time shr 5) and 63, (Time and 31) shl 1,0));
 end;
 end;
 {$else unix}
 {$else unix}
 var
 var
   y, mon, d, h, min, s: word;
   y, mon, d, h, min, s: word;
 begin
 begin
   EpochToLocal(FileDate,y,mon,d,h,min,s);
   EpochToLocal(FileDate,y,mon,d,h,min,s);
-  Result:=EncodeDate(y,mon,d) + EncodeTime(h,min,s,0);
+  Result:=ComposeDateTime(EncodeDate(y,mon,d),EncodeTime(h,min,s,0));
 end;
 end;
 {$endif unix}
 {$endif unix}