RE: [Gpsbabel-code] patch for calculating GMT
Brought to you by:
robertl
From: Martin F. <fo...@fo...> - 2003-01-07 06:02:39
|
Time is one of those things people can never agree on. My own preference is to have data storage in GMT and a GMT/Local option for display and use. That way there's less confusion when you cross time zones. The patched version is a cleaner implementation than my inline version. -----Original Message----- From: gps...@li... [mailto:gps...@li...]On Behalf Of Robert Lipe Sent: Monday, January 06, 2003 9:30 PM To: Martin Fouts Cc: gpsbabel Subject: Re: [Gpsbabel-code] patch for calculating GMT I took your idea and moved it to a function of its own (since the logic may be needed by other formats. This exercise did make me realize we probably shoudl standardize what's in the struct wpt itself. Is "creation time" local or GMT? Martin, Ron, does this patch work for you? Index: gpx.c =================================================================== RCS file: /cvsroot/gpsbabel/gpsbabel/gpx.c,v retrieving revision 1.26 diff -p -u -r1.26 gpx.c --- gpx.c 2 Jan 2003 04:07:24 -0000 1.26 +++ gpx.c 7 Jan 2003 05:25:35 -0000 @@ -388,19 +388,7 @@ gpx_end(void *data, const char *el) tm.tm_mon -= 1; tm.tm_year -= 1900; tm.tm_isdst = 1; - wpt_tmp->creation_time = mktime(&tm); -#if 0 - /* mktime assumes local time, and Z is gmtime */ - /* localtime will initialize timezone and daylight */ - /* 12/31/02 - RJL - unfortunately, this fix relies - * on non-ANSI extensions, so I've turned this off - * and reverted to the old way. - */ - localtime( &wpt_tmp->creation_time ); - wpt_tmp->creation_time -= timezone - (daylight?3600:0); -#else - wpt_tmp->creation_time = mktime(&tm); -#endif + wpt_tmp->creation_time = mktime(&tm) + get_tz_offset(); } if (in_wpt && in_gs_type && !in_gs_log) { wpt_tmp->gc_data.type = gs_mktype(cdatastr); Index: util.c =================================================================== RCS file: /cvsroot/gpsbabel/gpsbabel/util.c,v retrieving revision 1.13 diff -p -u -r1.13 util.c --- util.c 6 Jan 2003 23:58:53 -0000 1.13 +++ util.c 7 Jan 2003 05:25:35 -0000 @@ -109,6 +109,7 @@ fprintdms(FILE *file, const coord *c, in } fprintf(file, "%c%f\t", d, fabs(c->degrees)); } + void fatal(const char *fmt, ...) { @@ -196,5 +197,22 @@ si_round( double d ) } else { return (signed int)(d+0.5); + } +} + +/* + * Return a time_t suitable for adding to a time_t that is in GMT to + * make it a local time. + */ +signed int +get_tz_offset(void) +{ + time_t now = time(0); + time_t later = mktime(gmtime(&now)); + + if (later == -1) { + return 0; + } else { + return (signed int) difftime(now, later); } } Index: defs.h =================================================================== RCS file: /cvsroot/gpsbabel/gpsbabel/defs.h,v retrieving revision 1.25 diff -p -u -r1.25 defs.h --- defs.h 6 Jan 2003 23:33:13 -0000 1.25 +++ defs.h 7 Jan 2003 05:25:35 -0000 @@ -212,6 +212,7 @@ void *xcalloc(size_t nmemb, size_t size) void *xmalloc(size_t size); char *xstrdup(const char *s); void *rtrim(char *s); +signed int get_tz_offset(void); /* * PalmOS records like fixed-point numbers, which should be rounded ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ Gpsbabel-code mailing list Gps...@li... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |