Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timezone error in tNMEA0183Msg:makeTime(..) #23

Open
lsoltero opened this issue Apr 9, 2021 · 4 comments
Open

timezone error in tNMEA0183Msg:makeTime(..) #23

lsoltero opened this issue Apr 9, 2021 · 4 comments

Comments

@lsoltero
Copy link

lsoltero commented Apr 9, 2021

on a linux box working with RMC

input:
$GPRMC,203253.00,A,2642.08438,N,07859.51125,W,0.065,,061220,,,A*67

return from
if ( !NMEA0183ParseRMC_nc(NMEA0183Msg, GPSTime, Latitude, Longitude, COG, SOG, DaysSince1970, Variation, &DateTime)) {
return;
}

RMC: 06/12/2020 20:32:53, 26.701406, -78.991854, 0.000000, 0.065000, 18603, 0.000000, 1607304773

timezone set on my machine is EDT (GMT-4).

the issue is that DateTime == 1607304773 corresponds to
Monday, December 7, 2020 1:32:53 AM

and not 20:32:53 06/12/20

the problem is that makeTime is defined as
static inline time_t makeTime(tmElements_t &TimeElements) { return mktime(&TimeElements); }
which uses mktime which according to the docs
"The mktime() function converts a broken-down time structure, expressed as local time, to calendar time representation. "

so it uses timezone. since GPS time is always in UTC it seems that the correct definition for makeTime should be

static inline time_t makeTime(tmElements_t &TimeElements) { return mktime(&TimeElements) - timezone; }

i.e. subtract out the timezone to get back to GMT.

@lsoltero
Copy link
Author

lsoltero commented Apr 9, 2021

or better yet...

static inline time_t makeTime(tmElements_t &TimeElements) { return timegm(&TimeElements); }

@lsoltero
Copy link
Author

lsoltero commented Apr 9, 2021

a quick grep of the code shows localtime and mktime in other places. Might be a good to review the code for timezone issues.

@ttlappalainen
Copy link
Owner

I have to check - it is not that simple. In early days Arduino tim support was, what it was. It is important that any change does not cause incompamtibility to early versions so that it would suddently change behaviour in existing installations.

@ttlappalainen
Copy link
Owner

Arduino environment does not have timezone so that can not be used. I could bring timezone to library by with:

int32_t tNMEA0183Msg::GetTimeZone() {
  tmElements_t tme;
  SetYear(tme,1970);
  SetMonth(tme,1);
  SetDay(tme,2);
  SetHour(tme,0);
  SetMin(tme,0);
  SetSec(tme,0);

  return (int32_t )makeTime(tme)-SECS_PER_DAY;
}

If mktime implementation would have timezone in future also in Arduino, this should then work. Could you test that?
As addition there could be compiler definition
#if defined(linux)||defined(__linux)||defined(linux)
return timezone;
#else
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants