瀏覽代碼

* Added implementation for Julian date computaton.

git-svn-id: trunk@9604 -
mazen 17 年之前
父節點
當前提交
7c19e36595
共有 2 個文件被更改,包括 15 次插入13 次删除
  1. 8 12
      rtl/objpas/dateutil.inc
  2. 7 1
      rtl/objpas/sysutils/datih.inc

+ 8 - 12
rtl/objpas/dateutil.inc

@@ -1979,20 +1979,22 @@ end;
 {$warnings off}
 Function DateTimeToJulianDate(const AValue: TDateTime): Double;
 begin
-  NotYetImplemented('DateTimeToJulianDate');
+  DateTimeToJulianDate := AValue - JulianEpoch;
 end;
 
 
 Function JulianDateToDateTime(const AValue: Double): TDateTime;
 begin
-  NotYetImplemented('JulianDateToDateTime');
+  JulianDateToDateTime := AValue + JulianEpoch;
+  if(AValue <= 0) or (AValue >= 10000)then
+    JulianDateToDateTime := NaN;
 end;
 
 
 Function TryJulianDateToDateTime(const AValue: Double; var ADateTime: TDateTime): Boolean;
-
 begin
-  NotYetImplemented('TryJulianDateToDateTime');
+  ADateTime := JulianDateToDateTime(AValue);
+  TryJulianDateToDateTime := ADateTime <> NaN;
 end;
 
 
@@ -2020,20 +2022,14 @@ end;
   ---------------------------------------------------------------------}
 
 Function DateTimeToUnix(const AValue: TDateTime): Int64;
-var
-  Epoch:TDateTime;
 begin
-  Epoch:=EncodeDateTime( 1970, 1, 1, 0, 0, 0, 0 );
-  Result:=SecondsBetween( Epoch, AValue );
+  Result:=SecondsBetween(UnixEpoch, AValue);
 end;
 
 
 Function UnixToDateTime(const AValue: Int64): TDateTime;
-var
-  Epoch:TDateTime;
 begin
-  Epoch:=EncodeDateTime( 1970, 1, 1, 0, 0, 0, 0 );
-  Result:=IncSecond( Epoch, AValue );
+  Result:=IncSecond(UnixEpoch, AValue);
 end;
 
 

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

@@ -34,8 +34,14 @@ const
    SecsPerDay  = MinsPerDay * SecsPerMin;
    MSecsPerDay = SecsPerDay * MSecsPerSec;
 
+{TDateTime holds the date as the number of days since 30 Dec 1899, known as
+Microsoft Excel epoch}
+   JulianEpoch = TDateTime(-2415018.5);
+   UnixEpoch = JulianEpoch + TDateTime(2440587.5);
+
    DateDelta = 693594;        // Days between 1/1/0001 and 12/31/1899
-   UnixDateDelta = 25569;
+   UnixDateDelta = Trunc(UnixEpoch); //25569
+
 
    { True=Leapyear }
    MonthDays: array [Boolean] of TDayTable =