TryModifiedJulianDateToDateTime
A Julian date is commonly used by astronomers, geophysicists, and others, and used in computer science to calculate the difference between days, since all numbers in the system are consecutive integers. A Julian date (or Julian Day) is a number that refers to the number of days, including fractional days, that have elapsed since a particular historical point in time. The current Julian cycle started at Greenwich noon on January 1, 4713 B.C. (Gregorian calendar), and will end on January 22, 3268 A.D. For example, the Julian date for December 11, 1942 is 2430705; while December 12, 1942 is 2430706.
However, a modified Julian date is the number of days, including fractional days, since Greenwich midnight on November 17, 1858. Modified Julian dates are based on Julian dates, but adjusted to use midnight rather than noon as a starting point and to use a more recent date as a starting point.
The function TryModifiedJulianDateToDateTime attempts to convert a modified Julian Date into its corresponding TDateTime value, and tests whether a valid TDateTime value would be generated.
TryModifiedJulianDateToDateTime returns True if it can successfully convert AValue to a TDateTime value, and returns False if it cannot convert AValue into a TDateTime value. Where False has been returned, ADateTime reverts to 17-11-1858 00:00:00.000.
Declaration: function TryModifiedJulianDateToDateTime(const AValue: Double; out ADateTime: TDateTime): Boolean;
Here are some examples.
procedure
OnMapEvent(
var
Value:Variant);
var
TheDate : TDateTime;
TheJDate :
double
;
aGo :
boolean
;
begin
//Returns 'The modified Julian 60283.64920267 is 05-12-2023 15:34:51.111'
TheJDate :=
60283.64920267
;
aGo := TryModifiedJulianDateToDateTime(TheJDate, TheDate);
If
aGo =
True
then
LogInfo(
'The modified Julian '
+FloatToStr(TheJDate)+
' is '
+FormatDateTime(
'dd-mm-yyyy hh:nn:ss.zzz'
, TheDate))
else
LogInfo (
'Sorry - not a valid attempt.'
);
//Returns 'The modified Julian -60046 is 23-06-1694 00:00:00.000'
TheJDate := -
60046
;
aGo := TryModifiedJulianDateToDateTime(TheJDate, TheDate);
If
aGo =
True
then
LogInfo(
'The modified Julian '
+FloatToStr(TheJDate)+
' is '
+FormatDateTime(
'dd-mm-yyyy hh:nn:ss.zzz'
, TheDate))
else
LogInfo (
'Sorry - not a valid attempt.'
);
//Returns 'The modified Julian 48800.5 is 27-06-1992 12:00:00.000'
TheJDate :=
48800.5
;
aGo := TryModifiedJulianDateToDateTime(TheJDate, TheDate);
If
aGo =
True
then
LogInfo(
'The modified Julian '
+FloatToStr(TheJDate)+
' is '
+FormatDateTime(
'dd-mm-yyyy hh:nn:ss.zzz'
, TheDate))
else
LogInfo (
'Sorry - not a valid attempt.'
);
//Returns 'The modified Julian 0 is 17-11-1858 00:00:00.000'
TheJDate :=
99999999999999999999999999999
;
aGo := TryModifiedJulianDateToDateTime(TheJDate, TheDate);
If
aGo =
True
then
LogInfo(
'The modified Julian '
+FloatToStr(TheJDate)+
' is '
+FormatDateTime(
'dd-mm-yyyy hh:nn:ss.zzz'
, TheDate))
else
LogInfo (
'Sorry - not a valid attempt.'
);
end
;