[fpc-pascal] convert "epoch" to UTC
waldo kitty
wkitty42 at windstream.net
Mon Jan 16 20:06:45 CET 2012
On 1/16/2012 12:40, Sven Barth wrote:
> On 16.01.2012 17:57, waldo kitty wrote:
[TRIM]
>> looks like it should be easy to convert to pascal, too ;) just gotta
>> find out what that "floor" routine does ;)
>
> Well... I would say the same as FPC's "floor" routine (
> http://www.freepascal.org/docs-html/rtl/math/floor.html ) does ;)
hehe, exactly... and it was easy to convert, too...
function getJulianDay_Year(year:integer) : double;
var
dYear,
a,b,
dResult : double;
begin
dYear := year - 1;
A := Floor(dYear / 100);
B := 2 - A + Math.Floor(A / 4);
//The use of 30.600000000000001 is to correct for floating point rounding
problems
dResult := Floor(365.25 * dYear) + 1721422.9 + B;
getJulianDay_Year := dResult;
end;
function getJulianDay_SatEpoch(year:integer; dSatelliteEpoch:double) : double;
var
dResult : double;
begin
//Tidy up the year and put it into the correct century
year := year mod 100;
if (year < 57) then
year := year + 2000
else
year := year + 1900;
dResult := getJulianDay_Year(year);
dResult := dResult + dSatelliteEpoch;
getJulianDay_SatEpoch := dResult;
end;
with this TLE epoch number, 12013.93338171, ya feed it like so...
var
JEpoch : double;
DT : TDateTime;
[...]
JEpoch := getJulianDay_SatEpoch(12,013.93338171);
[...]
if TryJulianDateToDateTime(JEpoch,DT) then
writeln(FormatDateTime('YYYY MM DD hh:mm:ss',DT));
the above /should/ return 2012 01 14 22:24:04... i'm getting the right dates
back but all of the times are 00:00:00 :(
do JulianDateToDateTime and TryJulianDateToDateTime not do anything with hours,
minutes, seconds and milliseconds??
i'd give TryModifiedJulianDateToDateTime a try but the docs state that just
trying to use that routine raises an exception... is it going to handle the
hors, minutes, seconds, and milliseconds when it gets done or is it for some
other julian date format??
[ aside: where/how does one report documentation errors? PadLeft says to see
also PadLeft instead of PadRight ;) ]
More information about the fpc-pascal
mailing list