[time-nuts] GPS seconds conversion on an Arduino

Ben Hall kd5byb at gmail.com
Sun May 14 09:25:26 EDT 2017

On 5/14/2017 5:24 AM, Magnus Danielson wrote:
> You don't need to boil everything into one single number before 
> decomposing it into another form.
> If you start with the years, well, the different sums at most offset you 
> by 1 as you branch to the next year at somewhat misaligned dates.
> Similar with GPS weeks etc.

Good morning all,

I tried it by hand last night on two sheets of paper with a calculator 
and a frosty adult beverage...because I'm crazy like that.  I'll kill 
the suspense by saying I didn't get the right answer...so the rest of 
what I'm going to say has an error somewhere...but I think I can make 
the process work *if* the time library doesn't hold the answer.  (and I 
think it does)

I asked <https://www.andrews.edu/~tzs/timeconv/timeconvert.php> to give 
me current GPS time in seconds at known time, and then went to work. 
That same converter has a "tell me GPS seconds now" which agreed with 
the time in seconds coming from the TruePosition.

So...I figured out how many whole years (37...so its 2017), then used 
the remainder to figure out whole months (4...so its May 2017), the used 
the remainder to figure out days (13...so its 14 May 2017 because any 
remainder puts us into 14 May), then used the remainder to figure out 
hours (2...so its 14 May 2017 02:00), then used the remainder to figure 
out minutes (31...so its 14 May 2017 02:31), then used the remainder to 
figure out seconds (35...so its 14 May 2017 02:31:35), then subtracted 
18 leap seconds to get 14 May 2017 02:31:17.

Only problem was that it was 14 May 2017 00:31:17 UTC.  I'm not sure why 
the extra two hours...so I clearly got something *wrong*.

But, I think I should be able to do all this with, at most, single 
precision floating point math.  Maybe integers...but I've got to think 
about that as I'm not sure how integer math on the Arduino treats a 
decimal remainder.

Of course...all this is moot if I can get what I want out of the time 
library.  :)

thanks much,

More information about the time-nuts mailing list