* Added implementation for Julian date computaton.

git-svn-id: trunk@9604 -
This commit is contained in:
mazen 2007-12-31 16:34:45 +00:00
parent 5acb3649df
commit 7c19e36595
2 changed files with 15 additions and 13 deletions

View File

@ -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;

View File

@ -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 =