[fpc-pascal] convert "epoch" to UTC

waldo kitty wkitty42 at windstream.net
Mon Jan 16 23:57:31 CET 2012


On 1/16/2012 14:49, Sven Barth wrote:
> On 16.01.2012 20:06, waldo kitty wrote:
>> 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??
>
> A quick look at the code reveiled that it doesn't handle it.

i kinda figured that... however, here's a nice li'l :TripleFacePalm: for ya...

i tried to describe the format of the TLE Epoch number in an earlier post but i 
guess i pretty much failed... at least insofar as what the actual format is... 
here's what i posted previously...

[quote]
 >> i'm needing to convert a "UTC epoch" date to a "standard time string"... by
 >> that, i mean that i want to get something like "2011-01-13 22:24:04" out of
 >> the "epoch" number 12013.9338171...
 >>
 >> the above "epoch" number is (supposedly) built like this...
 >>
 >> 12 == 2012
 >> 013 == 13th day of the year
 >> .9338171 * 24 == 22.4116104 hours
 >> .4114104 * 60 == 24.696624 minutes
[/quote]

yes, that's the one where i dropped a '3' in the fractional part ;)

anyway, the format is like this...

*_TLE Epoch Format_*

eg: 12013.93338171

1. there are always 5 digits to the left of the decimal. the first two digits
    are the year of the epoch.

    if year<57 then year:=year+2000 else year:=year+1900

    in the above, 12 is the year which is 2012.

2. the next three digits (up to the decimal point) are the "day number of the
    year" of the TLE Epoch record.

    in the above, 013 is the day number of the year. feed this plus the year
    to a julian date routine to find the julian date number. in this example,
    we're looking for the julian date number for the 13th day of 2012.

3. the digits from the decimal point to the end are the fractional part of
    the day. these are /not/ in julian date or julian day format.

    in the above, .93338171 is the fractional part of the day. the time portion
    of the formula goes like this.

    fooo := frac(12013.93338171)
    rslt := fooo * 24    // 22.40116104
    hour := trunc(rslt)  // 22
    fooo := frac(rslt)   // .40116104
    rslt := fooo * 60    // 24.0696624
    mins := trunc(rslt)  // 24
    fooo := frac(rslt)   // .0696624
    rslt := fooo * 60    // 4.179744
    secs := trunc(rslt)  // 4
    fooo := frac(rslt)   // .179744
    rslt := fooo * 1000  // the more zeros, the more precision
    msec := trunc(rslt)  // 179

4. convert the julian date number from #2 to TDateTime. fill in the TDateTime
    time fields from #3. now EncodeDateTime and you'll have the proper numbers
    in a TDateTime record.

so what i ran into, besides the julian date routines not doing the time, but i 
was also sending the entire decimal number, without the year digits, to the 
julian date routine and that was just flat wrong since the fractional side 
wasn't a julian date fraction! ::TripleFacePalm::

so there's three pieces of data stored in that one "TLE Epoch" number and each 
has to be broken out and treated differently... now my answers finally agree 
with the programs i've been attempting to verify them against... i just couldn't 
see the forest for the trees and couldn't see the trees for all the leaves on'em 
:LOL:




More information about the fpc-pascal mailing list