From: robertlipe Date: Mon, 17 Jun 2013 02:07:08 +0000 (+0000) Subject: A ridiculously large commit as a checkpoint in refactoring the time_t + an int X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~11^2~560 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b4c18e7fb2e1cb7847c3ef99c19b0616901bcb15;p=gpsbabel.git A ridiculously large commit as a checkpoint in refactoring the time_t + an int for microseconds into a QDateTime to give us sensible interface to time beyond 1970 and 2032 and, more topically, more unified handling of sub-second time now that 10Hz GPSes aren't uncommon. This gets almost all of the accesses to wpt->creation_time into accessors (with overloads for int/time_t and QDateTime) and eliminates many of the problematic direct accesses to wpt->microseconds. --- diff --git a/gpsbabel/GPSBabel.xcodeproj/project.xcworkspace/xcuserdata/robertlipe.xcuserdatad/UserInterfaceState.xcuserstate b/gpsbabel/GPSBabel.xcodeproj/project.xcworkspace/xcuserdata/robertlipe.xcuserdatad/UserInterfaceState.xcuserstate index ca4bc1663..f504b6e2d 100644 Binary files a/gpsbabel/GPSBabel.xcodeproj/project.xcworkspace/xcuserdata/robertlipe.xcuserdatad/UserInterfaceState.xcuserstate and b/gpsbabel/GPSBabel.xcodeproj/project.xcworkspace/xcuserdata/robertlipe.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/gpsbabel/alan.cc b/gpsbabel/alan.cc index d855fd66e..c7a0c6b2e 100644 --- a/gpsbabel/alan.cc +++ b/gpsbabel/alan.cc @@ -505,7 +505,7 @@ static waypoint* get_wpt(struct wprdata* wprdata, unsigned n) WP = waypt_new(); WP->latitude = -pt2deg(wpt->pt.y); WP->longitude = pt2deg(wpt->pt.x); - WP->creation_time = unpack_time(wpt->date, wpt->time); + WP->SetCreationTime(unpack_time(wpt->date, wpt->time)); for (j=WPT_NAME_LEN-1; j >= 0 && wpt->name[j] == ' '; j--) {}; WP->shortname = xstrndup(wpt->name,j+1); for (j=WPT_COMMENT_LEN-1; j >= 0 && wpt->comment[j] == ' '; j--) {}; @@ -706,7 +706,7 @@ static int add_wpt(struct wprdata* wprdata, const waypoint* WP,int isroute) wpt->usecount = isroute ? 1 : 0; wpt->checked = isroute ? 0 : 1; wpt->reserved = 0; - pack_time(WP->creation_time, &(wpt->date), &(wpt->time)); + pack_time(WP->GetCreationTime(), &(wpt->date), &(wpt->time)); wpthdr->idx[hdr_idx] = wpt_idx; wpthdr->used[wpt_idx] = WPT_USED; diff --git a/gpsbabel/an1.cc b/gpsbabel/an1.cc index 480f29a41..63ca40309 100644 --- a/gpsbabel/an1.cc +++ b/gpsbabel/an1.cc @@ -703,7 +703,7 @@ static void Read_AN1_Waypoints(gbfile* f) wpt_tmp = waypt_new(); if (rec->creation_time) { - wpt_tmp->creation_time = rec->creation_time; + wpt_tmp->SetCreationTime(rec->creation_time); } wpt_tmp->longitude = -DecodeOrd(rec->lon); wpt_tmp->latitude = DecodeOrd(rec->lat); @@ -795,7 +795,7 @@ Write_One_AN1_Waypoint(const waypoint* wpt) } - rec->creation_time = rec->modification_time = wpt->creation_time; + rec->creation_time = rec->modification_time = wpt->GetCreationTime(); rec->lat = EncodeOrd(wpt->latitude); rec->lon = EncodeOrd(-wpt->longitude); rec->serial = serial++; diff --git a/gpsbabel/axim_gpb.cc b/gpsbabel/axim_gpb.cc index 424fc141d..3190576a3 100644 --- a/gpsbabel/axim_gpb.cc +++ b/gpsbabel/axim_gpb.cc @@ -114,7 +114,7 @@ decode_buff(const char* buff, route_head* track) tm.tm_year-=1900; tm.tm_mon--; - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); track_add_wpt(track, wpt); } diff --git a/gpsbabel/brauniger_iq.cc b/gpsbabel/brauniger_iq.cc index 30d0024b3..c0e725d9a 100644 --- a/gpsbabel/brauniger_iq.cc +++ b/gpsbabel/brauniger_iq.cc @@ -202,7 +202,7 @@ static int process_data(const unsigned char* data) case st_sample_alt: wpt = waypt_new(); wpt->latitude = wpt->longitude = 0.0; - wpt->creation_time = creation; + wpt->SetCreationTime(creation); creation += interval; wpt->altitude = (data[0] << 8) + data[1]; track_add_wpt(track, wpt); diff --git a/gpsbabel/cetus.cc b/gpsbabel/cetus.cc index 0e3925ca4..022d22cec 100644 --- a/gpsbabel/cetus.cc +++ b/gpsbabel/cetus.cc @@ -455,12 +455,12 @@ cetus_writewpt(const waypoint* wpt) rec = (struct cetus_wpt_s*) xcalloc(sizeof(*rec)+18 + NOTESZ + DESCSZ,1); - QDate date(wpt->creation_time.date()); + QDate date(wpt->GetCreationTime().date()); rec->day = date.day(); rec->mon = date.month(); be_write16(&rec->year, date.year()); - QTime time(wpt->creation_time.time()); + QTime time(wpt->GetCreationTime().time()); rec->min = time.minute(); rec->hour = time.hour(); rec->sec = time.second(); diff --git a/gpsbabel/coastexp.cc b/gpsbabel/coastexp.cc index 7aa72c74c..030ca04ea 100644 --- a/gpsbabel/coastexp.cc +++ b/gpsbabel/coastexp.cc @@ -292,7 +292,7 @@ ce_cdata(void* dta, const XML_Char* xml_s, int len) strncpy(secString, currentMark->created+13, 2); secString[2] = '\0'; t.tm_sec = atoi(secString); - currentMark->wp->creation_time = mkgmtime(&t); + currentMark->wp->SetCreationTime(mkgmtime(&t)); } } else if (inRoute) { currentRoute->r->rte_name = xstrdup(s); @@ -524,7 +524,7 @@ ce_wr_deinit(void) static char* ce_gen_creation_time(time_t tm) { - xml_fill_in_time(time_buffer, tm, 0, XML_SHORT_TIME); + xml_fill_in_time(time_buffer, tm, XML_SHORT_TIME); return time_buffer; } @@ -660,7 +660,7 @@ ce_mark_pr(const waypoint* wp) id = xml_buffer; } write_xml_entity_begin2(ofd, "\t", "Mark", - "created", ce_gen_creation_time(wp->creation_time), + "created", ce_gen_creation_time(wp->GetCreationTime()), "id", id); ce_waypt_pr(wp); write_xml_entity_end(ofd, "\t", "Mark"); diff --git a/gpsbabel/compegps.cc b/gpsbabel/compegps.cc index b078acbb7..9a8251b0b 100644 --- a/gpsbabel/compegps.cc +++ b/gpsbabel/compegps.cc @@ -207,7 +207,7 @@ parse_wpt(char* buff) case 5: if (has_time) { compegps_parse_time(c, &tm); - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); } case 6: wpt->altitude = atof(c); @@ -305,7 +305,7 @@ parse_trkpt(char* buff) break; case 5: compegps_parse_time(c, &tm); - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); break; case 7: wpt->altitude = atof(c); @@ -562,7 +562,7 @@ write_trkpt_cb(const waypoint* wpt) buff[0] = '\0'; if (wpt->creation_time != 0) { - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); struct tm tm = *gmtime(&tt); strftime(buff, sizeof(buff), "%d-%b-%y %H:%M:%S", &tm); diff --git a/gpsbabel/coto.cc b/gpsbabel/coto.cc index adf5775f5..b2141badb 100644 --- a/gpsbabel/coto.cc +++ b/gpsbabel/coto.cc @@ -243,7 +243,7 @@ coto_track_read(void) rec->time = be_read32(&rec->time); if (rec->time != 0) { rec->time -= 2082844800U; - wpt_tmp->creation_time = rec->time; + wpt_tmp->SetCreationTime(rec->time); } track_add_wpt(trk_head, wpt_tmp); } diff --git a/gpsbabel/cst.cc b/gpsbabel/cst.cc index aca0cac02..f13f9c9e7 100644 --- a/gpsbabel/cst.cc +++ b/gpsbabel/cst.cc @@ -292,7 +292,7 @@ cst_data_read(void) pow = lrtrim(++pow); strptime(pow, "%Y %m %d %H:%M:%S", &tm); - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); } wpt->latitude /= 100000.0; wpt->longitude /= 100000.0; diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc index 4af5ba618..a13028360 100644 --- a/gpsbabel/csv_util.cc +++ b/gpsbabel/csv_util.cc @@ -1173,37 +1173,36 @@ xcsv_parse_val(const char* s, waypoint* wpt, const field_map_t* fmp, /* TIME CONVERSIONS ***************************************************/ case XT_EXCEL_TIME: /* Time as Excel Time */ - wpt->creation_time = EXCEL_TO_TIMET(atof(s)); + wpt->SetCreationTime(EXCEL_TO_TIMET(atof(s))); break; case XT_TIMET_TIME: /* Time as time_t */ - wpt->creation_time = (time_t) atol(s); + wpt->SetCreationTime((time_t) atol(s)); break; case XT_TIMET_TIME_MS: { /* Time as time_t in milliseconds */ int s_len = strlen(s); if (s_len < 4) { /* less than 1 epochsecond, an unusual case */ - wpt->creation_time = (time_t) 0; - wpt->microseconds = (int) atoi(s) * 1000; + wpt->SetCreationTime(0,(int) atoi(s) * 1000); } else { char buff[32]; int off = s_len - 3; strncpy(buff, s, off); buff[off] = '\0'; - wpt->creation_time = (time_t) atol(buff); + time_t t = (time_t) atol(buff); s += off; strncpy(buff, s, 3); buff[3] = '\0'; - wpt->microseconds = (int) atoi(buff) * 1000; + wpt->SetCreationTime(t, (int) MILLI_TO_MICRO(atoi(buff))); } } break; case XT_YYYYMMDD_TIME: - wpt->creation_time = yyyymmdd_to_time(s); + wpt->SetCreationTime(yyyymmdd_to_time(s)); break; case XT_GMT_TIME: - wpt->creation_time += sscanftime(s, fmp->printfc, 1); + wpt->SetCreationTime(sscanftime(s, fmp->printfc, 1)); break; case XT_LOCAL_TIME: if (getenv("GPSBABEL_FREEZE_TIME")) { @@ -1224,7 +1223,7 @@ xcsv_parse_val(const char* s, waypoint* wpt, const field_map_t* fmp, wpt->creation_time = xml_parse_time(s, &wpt->microseconds); break; case XT_NET_TIME: { - time_t tt = wpt->creation_time; + time_t tt = wpt->GetCreationTime(); dotnet_time_to_time_t(atof(s), &tt, &wpt->microseconds); } break; @@ -1937,43 +1936,42 @@ xcsv_waypt_pr(const waypoint* wpt) /* TIME CONVERSIONS**************************************************/ case XT_EXCEL_TIME: /* creation time as an excel (double) time */ - writebuff(buff, fmp->printfc, TIMET_TO_EXCEL(wpt->creation_time)); + writebuff(buff, fmp->printfc, TIMET_TO_EXCEL(wpt->GetCreationTime())); break; case XT_TIMET_TIME: /* time as a time_t variable */ { - time_t tt = wpt->creation_time; + time_t tt = wpt->GetCreationTime(); writebuff(buff, fmp->printfc, tt); } break; case XT_TIMET_TIME_MS: { /* time as a time_t variable in milliseconds */ char tbuf[24]; - writetime(tbuf, sizeof(tbuf), "%s", wpt->creation_time, 0); + writetime(tbuf, sizeof(tbuf), "%s", wpt->GetCreationTime(), 0); char mbuf[32]; snprintf(mbuf, sizeof(mbuf), "%s%03d", tbuf, wpt->microseconds / 1000); writebuff(buff, "%s", mbuf); } break; case XT_YYYYMMDD_TIME: - writebuff(buff, fmp->printfc, time_to_yyyymmdd(wpt->creation_time)); + writebuff(buff, fmp->printfc, time_to_yyyymmdd(wpt->GetCreationTime())); break; case XT_GMT_TIME: - writetime(buff, sizeof buff, fmp->printfc, wpt->creation_time, 1); + writetime(buff, sizeof buff, fmp->printfc, wpt->GetCreationTime(), 1); break; case XT_LOCAL_TIME: - writetime(buff, sizeof buff, fmp->printfc, wpt->creation_time, 0); + writetime(buff, sizeof buff, fmp->printfc, wpt->GetCreationTime(), 0); break; case XT_HMSG_TIME: - writehms(buff, sizeof buff, fmp->printfc, wpt->creation_time, 1); + writehms(buff, sizeof buff, fmp->printfc, wpt->GetCreationTime(), 1); break; case XT_HMSL_TIME: - writehms(buff, sizeof buff, fmp->printfc, wpt->creation_time, 0); + writehms(buff, sizeof buff, fmp->printfc, wpt->GetCreationTime(), 0); break; case XT_ISO_TIME: - writetime(buff, sizeof buff, "%Y-%m-%dT%H:%M:%SZ", wpt->creation_time, 1); + writetime(buff, sizeof buff, "%Y-%m-%dT%H:%M:%SZ", wpt->GetCreationTime(), 1); break; case XT_ISO_TIME_MS: - xml_fill_in_time(buff, wpt->creation_time, - wpt->microseconds, XML_LONG_TIME); + xml_fill_in_time(buff, wpt->GetCreationTime(), XML_LONG_TIME); break; case XT_GEOCACHE_LAST_FOUND: writebuff(buff, fmp->printfc, time_to_yyyymmdd(wpt->gc_data->last_found)); diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 77d0ef73f..7256c5ca9 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -467,6 +467,7 @@ public: session(NULL), extra_data(NULL) { } public: + QString CreationTimeXML() const; queue Q; /* Master waypoint q. Not for use by modules. */ @@ -524,6 +525,13 @@ public: wp_flags wpt_flags; QString icon_descr; + + gpsbabel::DateTime GetCreationTime() const { return creation_time; } + void SetCreationTime(time_t t) { creation_time = t; } + void SetCreationTime(time_t t, int us) { + creation_time = t; + microseconds = us; + } gpsbabel::DateTime creation_time; int microseconds; /* Optional millionths of a second. */ @@ -1009,7 +1017,7 @@ const char* get_filename(const char* fname); /* extract the filename portion * #define str_iso8859_1_to_utf8(str) cet_str_iso8859_1_to_utf8((str)) /* this lives in gpx.c */ -time_t xml_parse_time(const char* cdatastr, int* microsecs); +gpsbabel::DateTime xml_parse_time(const char* cdatastr, int* microsecs); xml_tag* xml_findfirst(xml_tag* root, const char* tagname); xml_tag* xml_findnext(xml_tag* root, xml_tag* cur, const char* tagname); diff --git a/gpsbabel/delbin.cc b/gpsbabel/delbin.cc index aabd1a1de..5fd44609a 100644 --- a/gpsbabel/delbin.cc +++ b/gpsbabel/delbin.cc @@ -998,7 +998,7 @@ decode_waypoint(const void* data) const char* s; float f; - wp->creation_time = decode_time(&p->year); + wp->SetCreationTime(decode_time(&p->year)); wp->latitude = delbin_rad2deg(le_read32(p->latitude)); wp->longitude = delbin_rad2deg(le_read32(p->longitude)); f = le_read_float(p->elevation); @@ -1414,7 +1414,7 @@ write_waypoint(const waypoint* wp) waypoint_i++; le_write32(p->total, waypoint_n); le_write32(p->index, waypoint_i); - encode_time(wp->creation_time, &p->year); + encode_time(wp->GetCreationTime(), &p->year); le_write32(p->latitude, delbin_deg2rad(wp->latitude)); le_write32(p->longitude, delbin_deg2rad(wp->longitude)); if (wp->altitude > unknown_alt) { @@ -1529,7 +1529,7 @@ decode_track_point(const void* data, unsigned* wp_array_i, unsigned max_point) waypoint* wp = waypt_new(); float elev = le_read_float(p->point[i].elevation); wp_array[j] = wp; - wp->creation_time = decode_time(&p->point[i].year); + wp->SetCreationTime(decode_time(&p->point[i].year)); wp->latitude = delbin_rad2deg(le_read32(p->point[i].latitude)); wp->longitude = delbin_rad2deg(le_read32(p->point[i].longitude)); if (elev > UNKNOWN_ELEV) { @@ -1713,7 +1713,7 @@ write_track_points(void) le_write32(p->index, i + 1); } assert(p); - encode_time(wp->creation_time, &p->point[j].year); + encode_time(wp->GetCreationTime(), &p->point[j].year); le_write32(p->point[j].latitude, delbin_deg2rad(wp->latitude)); le_write32(p->point[j].longitude, delbin_deg2rad(wp->longitude)); f = UNKNOWN_ELEV; @@ -1793,7 +1793,7 @@ write_track_end(const route_head* track) if (track->rte_name) { strncpy(p->name, track->rte_name, sizeof(p->name) - 1); } else { - sprintf(p->name, "%lu", (long)wp_array[0]->creation_time); + sprintf(p->name, "%lu", (long)wp_array[0]->GetCreationTime()); } le_write32(p->total_points, waypoint_n); encode_time(current_time(), &p->year); @@ -2186,7 +2186,7 @@ write_route_end(const route_head* route) if (route->rte_name) { strncpy(p->name, route->rte_name, sizeof(p->name) - 1); } else { - sprintf(p->name, "%lu", (long)wp_array[0]->creation_time); + sprintf(p->name, "%lu", (long)wp_array[0]->GetCreationTime()); } p->type = 0; le_write32(p->total_route_point, route_point_n); @@ -2222,7 +2222,7 @@ decode_navmsg(const void* data) t.tm_hour = p->hour; t.tm_min = p->minute; t.tm_sec = p->second; - wp->creation_time = mkgmtime(&t); + wp->SetCreationTime(mkgmtime(&t)); wp->sat = p->satellites; wp->latitude = le_read_double(p->latitude); wp->longitude = le_read_double(p->longitude); diff --git a/gpsbabel/delgpl.cc b/gpsbabel/delgpl.cc index 29006c7ff..a51c1d870 100644 --- a/gpsbabel/delgpl.cc +++ b/gpsbabel/delgpl.cc @@ -71,7 +71,7 @@ gpl_read(void) if (wpt_tmp->altitude <= unknown_alt + 1) { wpt_tmp->altitude = unknown_alt; } - wpt_tmp->creation_time = le_read32(&gp.tm); + wpt_tmp->SetCreationTime(le_read32(&gp.tm)); switch (le_read32(&gp.status)) { case 1: @@ -154,7 +154,7 @@ gpl_trackpt(const waypoint* wpt) le_write_double(&gp.alt, alt_feet); le_write_double(&gp.speed, speed); le_write_double(&gp.heading, heading); - le_write32(&gp.tm, wpt->creation_time); + le_write32(&gp.tm, wpt->GetCreationTime()); gbfwrite(&gp, sizeof(gp), 1, gplfile_out); } diff --git a/gpsbabel/destinator.cc b/gpsbabel/destinator.cc index 1de34ea3d..f56a08875 100644 --- a/gpsbabel/destinator.cc +++ b/gpsbabel/destinator.cc @@ -332,8 +332,8 @@ destinator_read_trk(void) snprintf(buff, sizeof(buff), "%06d%.f", date, time); strptime(buff, "%d%m%y%H%M%S", &tm); - wpt->creation_time = mkgmtime(&tm); - wpt->microseconds = ((int)time % 1000) * 1000; + wpt->SetCreationTime(mkgmtime(&tm), + ((int)time % 1000) * 1000); if (wpt->fix > 0) { wpt->fix = (fix_type)(wpt->fix + 1); @@ -438,7 +438,7 @@ destinator_trkpt_disp(const waypoint* wpt) struct tm tm; double time; int date; - const time_t ct = wpt->creation_time; + const time_t ct = wpt->GetCreationTime(); tm = *gmtime(&ct); tm.tm_mon += 1; tm.tm_year -= 100; diff --git a/gpsbabel/dg-100.cc b/gpsbabel/dg-100.cc index b64d43868..b6ffbd9e7 100644 --- a/gpsbabel/dg-100.cc +++ b/gpsbabel/dg-100.cc @@ -282,7 +282,7 @@ process_gpsfile(gbuint8 data[], route_head** track) if (style >= 1) { bintime = be_read32(data + i + 8) & 0x7FFFFFFF; bindate = be_read32(data + i + 12); - wpt->creation_time = bintime2utc(bindate, bintime); + wpt->SetCreationTime(bintime2utc(bindate, bintime)); /* The device presents the speed as a fixed-point number * with a scaling factor of 100, in km/h. * The waypoint struct wants the speed as a diff --git a/gpsbabel/exif.cc b/gpsbabel/exif.cc index 5e906b013..73450a9d0 100644 --- a/gpsbabel/exif.cc +++ b/gpsbabel/exif.cc @@ -1503,7 +1503,7 @@ exif_write(void) struct tm tm; char buf[32]; - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = *gmtime(&tt); tm.tm_year += 1900; diff --git a/gpsbabel/g7towin.cc b/gpsbabel/g7towin.cc index b910d6146..cf48069af 100644 --- a/gpsbabel/g7towin.cc +++ b/gpsbabel/g7towin.cc @@ -105,7 +105,7 @@ parse_line(char* buff, int index, const char* delimiter, waypoint* wpt) if (cerr == NULL) { fatal(MYNAME ": Unable to convert date (%s)!\n", cin); } - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); break; case WAYPT__OFS + 1: @@ -317,7 +317,7 @@ parse_waypt(char* buff) if (cerr == NULL) { fatal(MYNAME ": Unable to convert date (%s)!\n", buff); } - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); /* go over time stamp */ i = 5; diff --git a/gpsbabel/garmin.cc b/gpsbabel/garmin.cc index c865171f6..60eadbf65 100644 --- a/gpsbabel/garmin.cc +++ b/gpsbabel/garmin.cc @@ -345,7 +345,7 @@ waypt_read(void) wpt->longitude = gps_save_lon; wpt->shortname = xstrdup("Position"); if (gps_save_time) { - wpt->creation_time = gps_save_time; + wpt->SetCreationTime(gps_save_time); } waypt_add(wpt); return; @@ -390,7 +390,7 @@ waypt_read(void) wpt_tmp->altitude = way[i]->alt; } if (way[i]->time_populated) { - wpt_tmp->creation_time = way[i]->time; + wpt_tmp->SetCreationTime(way[i]->time); } #if SOON garmin_fs_garmin_after_read(way[i], wpt_tmp, gps_waypt_type); @@ -418,7 +418,7 @@ unsigned int checkWayPointIsAtSplit(waypoint* wpt, GPS_PLap* laps, int nlaps) int i; for (i=(nlaps-1); i >= 0; i--) { GPS_PLap lap = laps[i]; - time_t delta = lap->start_time - wpt->creation_time; + time_t delta = lap->start_time - wpt->GetCreationTime(); if ((delta >= -1) && (delta <= 1)) { result = 1; break; @@ -503,7 +503,7 @@ track_read(void) wpt->heartrate = array[i]->heartrate; wpt->cadence = array[i]->cadence; wpt->shortname = xstrdup(array[i]->trk_ident); - wpt->creation_time = array[i]->Time; + wpt->SetCreationTime(array[i]->Time); wpt->wpt_flags.is_split = checkWayPointIsAtSplit(wpt, laps, nlaps); wpt->wpt_flags.new_trkseg = next_is_new_trkseg; @@ -985,7 +985,7 @@ waypoint_prepare(void) tx_waylist[i]->alt = wpt->altitude; } if (wpt->creation_time) { - tx_waylist[i]->time = wpt->creation_time; + tx_waylist[i]->time = wpt->GetCreationTime(); tx_waylist[i]->time_populated = 1; } if (category) { diff --git a/gpsbabel/garmin_device_xml.h b/gpsbabel/garmin_device_xml.h index 1edd98ded..4ee325c6b 100644 --- a/gpsbabel/garmin_device_xml.h +++ b/gpsbabel/garmin_device_xml.h @@ -1437,7 +1437,7 @@ gpx_write_common_position(const waypoint* waypointp, const char* indent) indent, waypointp->altitude); } if (waypointp->creation_time) { - xml_write_time(ofd, waypointp->creation_time, waypointp->microseconds, "time"); + xml_write_time(ofd, waypointp->GetCreationTime(), waypointp->microseconds, "time"); } } diff --git a/gpsbabel/garmin_txt.cc b/gpsbabel/garmin_txt.cc index b66e6da4d..88500f684 100644 --- a/gpsbabel/garmin_txt.cc +++ b/gpsbabel/garmin_txt.cc @@ -255,11 +255,11 @@ prework_wpt_cb(const waypoint* wpt) waypoint* prev = cur_info->prev_wpt; if (prev != NULL) { - cur_info->time += (wpt->creation_time - prev->creation_time); + cur_info->time += (wpt->GetCreationTime() - prev->GetCreationTime()); cur_info->length += waypt_distance_ex(prev, wpt); } else { cur_info->first_wpt = (waypoint*)wpt; - cur_info->start = wpt->creation_time; + cur_info->start = wpt->GetCreationTime(); } cur_info->prev_wpt = (waypoint*)wpt; cur_info->count++; @@ -618,7 +618,7 @@ write_waypt(const waypoint* wpt) print_string("%s\t", GMSD_GET(state, "")); country = gt_get_icao_country(GMSD_GET(cc, "")); print_string("%s\t", (country != NULL) ? country : ""); - print_date_and_time(wpt->creation_time, 0); + print_date_and_time(wpt->GetCreationTime(), 0); print_string("%s\t", wpt->hasLink() ? wpt->url : ""); print_categories(GMSD_GET(category, 0)); @@ -719,7 +719,7 @@ track_disp_wpt_cb(const waypoint* wpt) gbfprintf(fout, "Trackpoint\t"); print_position(wpt); - print_date_and_time(wpt->creation_time, 0); + print_date_and_time(wpt->GetCreationTime(), 0); if IS_VALID_ALT(wpt->altitude) { print_distance(wpt->altitude, 1, 0, 0); } @@ -733,7 +733,7 @@ track_disp_wpt_cb(const waypoint* wpt) if (prev != NULL) { float temp; gbfprintf(fout, "\t"); - delta = wpt->creation_time - prev->creation_time; + delta = wpt->GetCreationTime() - prev->GetCreationTime(); temp = WAYPT_GET(wpt, temperature, -999); if (temp != -999) { print_temperature(temp); diff --git a/gpsbabel/garmin_xt.cc b/gpsbabel/garmin_xt.cc index 38fedfa04..6b07e95b4 100644 --- a/gpsbabel/garmin_xt.cc +++ b/gpsbabel/garmin_xt.cc @@ -298,7 +298,7 @@ format_garmin_xt_proc_strk(void) wpt->latitude = PrevLat; /* Degrees */ wpt->longitude = PrevLon; /* Degrees */ wpt->altitude = PrevEle; /* Meters. */ - wpt->creation_time = Time; /* Unix Time adjusted to Garmin time */ + wpt->SetCreationTime(Time); /* Unix Time adjusted to Garmin time */ // add way point to the track track_add_wpt(tmp_track, wpt); @@ -324,7 +324,7 @@ format_garmin_xt_proc_strk(void) wpt->latitude = PrevLat; /* Degrees */ wpt->longitude = PrevLon; /* Degrees */ wpt->altitude = PrevEle; /* Meters. */ - wpt->creation_time = Time; /* Unix Time adjusted to Garmin time */ + wpt->SetCreationTime(Time); /* Unix Time adjusted to Garmin time */ // add way point to the track track_add_wpt(tmp_track, wpt); @@ -396,7 +396,7 @@ format_garmin_xt_proc_atrk(void) wpt->latitude = LatF*180/16777216; /* Degrees */ wpt->longitude = LonF*360/16777216; /* Degrees */ wpt->altitude = AltF; /* Meters. */ - wpt->creation_time = Tim; /* Unix Time adjusted to Garmin time */ + wpt->SetCreationTime(Tim); /* Unix Time adjusted to Garmin time */ track_add_wpt(track, wpt); } diff --git a/gpsbabel/gcdb.cc b/gpsbabel/gcdb.cc index 76a744b06..e24993e70 100644 --- a/gpsbabel/gcdb.cc +++ b/gpsbabel/gcdb.cc @@ -154,7 +154,7 @@ if (!strncmp("date", rec->dbfld[i].fldname,4)) { time_t tm; tm = be_read32(recdata) * 24 * 3600; tm -= EPOCH_1904; -wpt->creation_time = tm; +wpt->SetCreationTime(tm); warning("date %d\n", tm); } break; @@ -266,7 +266,7 @@ gcdb_add_to_rec(rec, "terr", RECTYPE_TEXT, tbuf); * not the cache creation date. */ if (wpt->creation_time) { -gcdb_add_to_rec(rec, "date", RECTYPE_DATE, (void*) wpt->creation_time); +gcdb_add_to_rec(rec, "date", RECTYPE_DATE, (void*) wpt->GetCreationTime()); } #endif diff --git a/gpsbabel/gdb.cc b/gpsbabel/gdb.cc index 3d679b826..b3508ff3b 100644 --- a/gpsbabel/gdb.cc +++ b/gpsbabel/gdb.cc @@ -1406,7 +1406,7 @@ write_waypoint( FWRITE_i16(GMSD_GET(category, gdb_category)); FWRITE_DBL(WAYPT_GET(wpt, temperature, 0), 0); - FWRITE_TIME(wpt->creation_time); + FWRITE_TIME(wpt->GetCreationTime()); /* VERSION DEPENDENT CODE */ if (gdb_ver >= GDB_VER_3) { @@ -1588,7 +1588,7 @@ write_track(const route_head* trk, const char* trk_name) FWRITE_LATLON(wpt->latitude); FWRITE_LATLON(wpt->longitude); FWRITE_DBL(wpt->altitude, unknown_alt); - FWRITE_TIME(wpt->creation_time); + FWRITE_TIME(wpt->GetCreationTime()); d = WAYPT_GET(wpt, depth, unknown_alt); FWRITE_DBL(d, unknown_alt); d = WAYPT_GET(wpt, temperature, -99999); diff --git a/gpsbabel/geoniche.cc b/gpsbabel/geoniche.cc index 482e76a14..e2d92d844 100644 --- a/gpsbabel/geoniche.cc +++ b/gpsbabel/geoniche.cc @@ -378,7 +378,7 @@ geoniche_read_asc(void) tm.tm_year -= 1900; sscanf(timestr, "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec); if (tm.tm_year >= 1970) { - wpt->creation_time = mktime(&tm); + wpt->SetCreationTime(mktime(&tm)); } xfree(datestr); xfree(timestr); @@ -540,7 +540,7 @@ geoniche_read_bin(void) waypt->shortname = xstrdup(vdata + 63); waypt->altitude = altitude; - waypt->creation_time = mkgmtime(&created); + waypt->SetCreationTime(mkgmtime(&created)); GPS_Math_DegMin_To_Deg(latdeg, lat, &waypt->latitude); GPS_Math_DegMin_To_Deg(londeg, lon, &waypt->longitude); @@ -749,7 +749,7 @@ geoniche_writewpt(const waypoint* wpt) id = rec_ct; } - tx = (wpt->creation_time != 0) ? wpt->creation_time : gpsbabel_time; + tx = (wpt->GetCreationTime() != 0) ? wpt->GetCreationTime() : gpsbabel_time; if (tx == 0) { /* maybe zero during testo (freezed time) */ strcpy(datestr, "01/01/1904"); /* this seems to be the uninitialized date value for geoniche */ strcpy(timestr, "00:00:00"); diff --git a/gpsbabel/ggv_log.cc b/gpsbabel/ggv_log.cc index 5994bb6c1..c2a3572e8 100644 --- a/gpsbabel/ggv_log.cc +++ b/gpsbabel/ggv_log.cc @@ -179,7 +179,7 @@ ggv_log_read(void) tm.tm_year -= 1900; if (tm.tm_mon > 0) { tm.tm_mon--; - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); } } @@ -224,7 +224,7 @@ ggv_log_track_head_cb(const route_head* trk) lonsec = 60.0 * (lonmin - floor(lonmin)); if (wpt->creation_time > 0) { - tm = *gmtime(&wpt->creation_time); + tm = *gmtime(&wpt->GetCreationTime()); tm.tm_mon += 1; tm.tm_year += 1900; } else { diff --git a/gpsbabel/glogbook.cc b/gpsbabel/glogbook.cc index b42b6abeb..cbdd07733 100644 --- a/gpsbabel/glogbook.cc +++ b/gpsbabel/glogbook.cc @@ -96,7 +96,7 @@ glogbook_waypt_pr(const waypoint* wpt) } gbfprintf(ofd, " \n"); gbfprintf(ofd, " "); - xml_write_time(ofd, wpt->creation_time, wpt->microseconds, "Time"); + xml_write_time(ofd, wpt->GetCreationTime(), wpt->microseconds, "Time"); gbfprintf(ofd, " \n"); } @@ -147,7 +147,7 @@ void gl_trk_pnt_e(const char* args, const char** unused) void gl_trk_utc(const char* args, const char** unused) { - wpt_tmp->creation_time = xml_parse_time(args, &wpt_tmp->microseconds); + wpt_tmp->SetCreationTime(xml_parse_time(args, &wpt_tmp->microseconds)); } void gl_trk_lat(const char* args, const char** unused) diff --git a/gpsbabel/gnav_trl.cc b/gpsbabel/gnav_trl.cc index dc5216dee..e15e6422d 100644 --- a/gpsbabel/gnav_trl.cc +++ b/gpsbabel/gnav_trl.cc @@ -100,7 +100,7 @@ gnav_trl_read(void) wpt = waypt_new(); - wpt->creation_time = le_read32(&rec.time); + wpt->SetCreationTime(le_read32(&rec.time)); wpt->latitude = le_read_float(&rec.lat); wpt->longitude = le_read_float(&rec.lon); wpt->altitude = read_altitude(&rec.alt); @@ -118,7 +118,7 @@ gnav_trl_write_trkpt(const waypoint* wpt) { gnav_trl_t rec; - le_write32(&rec.time, wpt->creation_time); + le_write32(&rec.time, wpt->GetCreationTime()); le_write_float(&rec.lat, wpt->latitude); le_write_float(&rec.lon, wpt->longitude); if (wpt->altitude != unknown_alt) { diff --git a/gpsbabel/gopal.cc b/gpsbabel/gopal.cc index 59e9cdfb1..10c3b323d 100644 --- a/gpsbabel/gopal.cc +++ b/gpsbabel/gopal.cc @@ -308,7 +308,7 @@ gopal_read(void) //calculate the speed to reach this waypoint from the last. This way I try to sort out invalid waypoints speed=0; if (lastwpt !=NULL) { - speed=3.6*radtometers(gcdist(RAD(lastwpt->latitude), RAD(lastwpt->longitude), RAD(wpt->latitude), RAD(wpt->longitude))) / abs(wpt->creation_time - lastwpt->creation_time); + speed=3.6*radtometers(gcdist(RAD(lastwpt->latitude), RAD(lastwpt->longitude), RAD(wpt->latitude), RAD(wpt->longitude))) / abs(wpt->creation_time - lastwpt->GetCreationTime()); //printf("speed line %d %lf \n",line,speed); } /* Error handling: in the tracklog of my device sometimes "jump" waypoints ;-) */ @@ -366,7 +366,7 @@ gopal_write_waypt(const waypoint* wpt) } } //MSVC handles time_t as int64, gcc and mac only int32, so convert it: - timestamp=(unsigned long)wpt->creation_time; + timestamp=(unsigned long)wpt->GetCreationTime(); gbfprintf(fout, "%lu, %s, %lf, %lf, %5.1lf, %8.5lf, %d, %lf, %d\n",timestamp,tbuffer, wpt->longitude, wpt->latitude,wpt->altitude, wpt->speed,fix,wpt->hdop,wpt->sat); } diff --git a/gpsbabel/gpilots.cc b/gpsbabel/gpilots.cc index 56938403e..4e732359a 100644 --- a/gpsbabel/gpilots.cc +++ b/gpsbabel/gpilots.cc @@ -313,7 +313,7 @@ data_read(void) * Garmin/GPilotS count seconds from "UTC 12:00 AM December 31 1989". * gpsbabel counts seconds from "UTC 12:00 AM January 1 1970". */ - wpt_tmp->creation_time = be_read32(&tp_cust->time) + 631065600; + wpt_tmp->SetCreationTime(be_read32(&tp_cust->time) + 631065600); fi.i = be_read32(&tp_cust->alt); wpt_tmp->altitude = fi.f; track_add_wpt(track_head, wpt_tmp); diff --git a/gpsbabel/gpssim.cc b/gpsbabel/gpssim.cc index 79b4943e1..abf9728e7 100644 --- a/gpsbabel/gpssim.cc +++ b/gpsbabel/gpssim.cc @@ -126,7 +126,7 @@ gpssim_write_pt(const waypoint* wpt) int hms, ymd; struct tm* tm; - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = gmtime(&tt); hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec; ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year; diff --git a/gpsbabel/gpsutil.cc b/gpsbabel/gpsutil.cc index b1c41445f..7e8b621ce 100644 --- a/gpsbabel/gpsutil.cc +++ b/gpsbabel/gpsutil.cc @@ -114,7 +114,7 @@ data_read(void) wpt_tmp->altitude = alt; wpt_tmp->shortname = sn; wpt_tmp->description = xstrdup(desc); - wpt_tmp->creation_time = now; + wpt_tmp->SetCreationTime(now); if (latdir == 'S') { lat = -lat; diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 212aeca59..03fe746b5 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -31,6 +31,7 @@ static XML_Parser psr; #include //#include #include +#include static xml_tag* cur_tag; @@ -844,7 +845,7 @@ gs_get_container(geocache_container t) return "Unknown"; } -time_t +gpsbabel::DateTime xml_parse_time(const char* cdatastr, int* microsecs) { int off_hr = 0; @@ -909,7 +910,18 @@ xml_parse_time(const char* cdatastr, int* microsecs) xfree(timestr); - return rv; + // TOOD(robertlipe) - This really is a groady hack to shim in + // the old interface (which had an explicit microsecs pointer argument + // as an optional output value) and the new form which uses QDateTime + // but, because of the above hackery, doesn't really work outside 1970 + // 2038 but which we can't replace until Steven upgrades Qt. + // Baby steps. + QDateTime dt = QDateTime::fromTime_t(rv); + if (microsecs) { + dt = dt.addMSecs(*microsecs / 1000); +// qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz") << " ZZZ " << *microsecs; + } + return dt; } static void @@ -1131,7 +1143,7 @@ gpx_end(void* data, const XML_Char* xml_el) case tt_wpt_time: case tt_trk_trkseg_trkpt_time: case tt_rte_rtept_time: - wpt_tmp->creation_time = xml_parse_time(cdatastrp, &wpt_tmp->microseconds); + wpt_tmp->SetCreationTime(xml_parse_time(cdatastrp, &wpt_tmp->microseconds)); break; case tt_wpt_cmt: case tt_rte_rtept_cmt: @@ -1437,7 +1449,7 @@ fprint_xml_chain(xml_tag* tag, const waypoint* wpt) strcmp(tag->tagname, "groundspeak:cache") == 0) { char time_string[64]; xml_fill_in_time(time_string, wpt->gc_data->exported, - 0, XML_LONG_TIME); + XML_LONG_TIME); if (time_string[0]) { writer.writeTextElement("time", time_string); } @@ -1569,15 +1581,8 @@ gpx_write_common_position(const waypoint* waypointp) if (waypointp->altitude != unknown_alt) { writer.writeTextElement("ele", QString::number(waypointp->altitude, 'f', 6)); } - if (waypointp->creation_time) { - char time_string[64]; - // FIXME: Eventually use creation_time.toString() - xml_fill_in_time(time_string, waypointp->creation_time, - waypointp->microseconds, XML_LONG_TIME); - if (time_string[0]) { - writer.writeTextElement("time", time_string); - } - } + QString t = waypointp->CreationTimeXML(); + writer.writeOptionalTextElement("time", t); } static void @@ -1946,7 +1951,7 @@ gpx_write(void) now = current_time(); char time_string[64]; - xml_fill_in_time(time_string, now, 0, XML_LONG_TIME); + xml_fill_in_time(time_string, now, XML_LONG_TIME); if (time_string[0]) { writer.writeTextElement("time", time_string); } diff --git a/gpsbabel/gtm.cc b/gpsbabel/gtm.cc index 46b14b732..830465f3b 100644 --- a/gpsbabel/gtm.cc +++ b/gpsbabel/gtm.cc @@ -740,7 +740,7 @@ static void write_waypt(const waypoint* wpt) fwrite_integer(file_out, icon_from_descr(wpt->icon_descr)); fwrite_byte(file_out, 3); if (wpt->creation_time) { - fwrite_long(file_out, wpt->creation_time-EPOCH89DIFF); + fwrite_long(file_out, wpt->GetCreationTime()-EPOCH89DIFF); } else { fwrite_long(file_out, 0); } @@ -763,7 +763,7 @@ static void write_trk_waypt(const waypoint* wpt) { fwrite_double(file_out, wpt->latitude); fwrite_double(file_out, wpt->longitude); - fwrite_long(file_out, wpt->creation_time-EPOCH89DIFF); + fwrite_long(file_out, wpt->GetCreationTime()-EPOCH89DIFF); fwrite_byte(file_out, start_new); if (wpt->altitude == unknown_alt) { fwrite_single(file_out, unknown_alt_gtm); diff --git a/gpsbabel/gtrnctr.cc b/gpsbabel/gtrnctr.cc index e776aaa6f..57e4d8eda 100644 --- a/gpsbabel/gtrnctr.cc +++ b/gpsbabel/gtrnctr.cc @@ -261,18 +261,18 @@ static void gtc_study_lap(const waypoint* wpt) { if (wpt->creation_time && (gtc_least_time == 0)) { - gtc_least_time = wpt->creation_time; + gtc_least_time = wpt->GetCreationTime(); gtc_start_lat = wpt->latitude; gtc_start_long = wpt->longitude; } - if (wpt->creation_time && (gtc_least_time > wpt->creation_time)) { - gtc_least_time = wpt->creation_time; + if (wpt->creation_time && (gtc_least_time > wpt->GetCreationTime())) { + gtc_least_time = wpt->GetCreationTime(); gtc_start_lat = wpt->latitude; gtc_start_long = wpt->longitude; } if (wpt->creation_time > gtc_most_time) { - gtc_most_time = wpt->creation_time; + gtc_most_time = wpt->GetCreationTime(); gtc_end_lat = wpt->latitude; gtc_end_long = wpt->longitude; } @@ -288,12 +288,10 @@ gtc_waypt_pr(const waypoint* wpt) } if (wpt->creation_time) { - char time_string[100]; - xml_fill_in_time(time_string, wpt->creation_time, wpt->microseconds, - XML_LONG_TIME); - if (time_string[0]) { + QString time_string = wpt->CreationTimeXML(); + if (!time_string.isEmpty()) { gtc_write_xml(0, "\n", - time_string); + qPrintable(time_string)); } } if (wpt->latitude && wpt->longitude) { @@ -394,7 +392,7 @@ gtc_act_hdr(const route_head* rte) route_disp(rte, gtc_study_lap); if (gtc_least_time) { char time_string[100]; - xml_fill_in_time(time_string, gtc_least_time, 0, XML_LONG_TIME); + xml_fill_in_time(time_string, gtc_least_time, XML_LONG_TIME); gtc_write_xml(0, "%s\n", time_string); gtc_write_xml(1, "\n", time_string); } else { diff --git a/gpsbabel/hiketech.cc b/gpsbabel/hiketech.cc index bab21cdc8..019f43664 100644 --- a/gpsbabel/hiketech.cc +++ b/gpsbabel/hiketech.cc @@ -129,7 +129,7 @@ hiketech_trkpt_pr(const waypoint* waypointp) { gbfprintf(ofd, " \n"); if (waypointp->creation_time) { - hiketech_print_utc(waypointp->creation_time, " ", "utc"); + hiketech_print_utc(waypointp->GetCreationTime(), " ", "utc"); } gbfprintf(ofd, " %f\n", waypointp->latitude); gbfprintf(ofd, " %f\n", waypointp->longitude); @@ -259,7 +259,7 @@ void ht_trk_utc(const char* args, const char** unused) utc = mkgmtime(&tm); - wpt_tmp->creation_time = utc; + wpt_tmp->SetCreationTime(utc); } static diff --git a/gpsbabel/holux.cc b/gpsbabel/holux.cc index 3def99f58..96fcf8af1 100644 --- a/gpsbabel/holux.cc +++ b/gpsbabel/holux.cc @@ -120,7 +120,7 @@ static void data_read(void) wpt_tmp->shortname = xstrdup(name); wpt_tmp->description = xstrdup(desc); - wpt_tmp->creation_time = 0; + wpt_tmp->SetCreationTime(0); if (pWptHxTmp->date.year) { #if 0 /* Unless there's some endian swapping that I don't see, @@ -140,7 +140,7 @@ static void data_read(void) tm.tm_mday = pWptHxTmp->date.day; tm.tm_mon = pWptHxTmp->date.month - 1; tm.tm_year = pWptHxTmp->date.year - 1900; - wpt_tmp->creation_time = mktime(&tm); + wpt_tmp->SetCreationTime(mktime(&tm)); } lon = le_read32(&pWptHxTmp->pt.iLongitude) / 36000.0; @@ -227,8 +227,8 @@ static void holux_disp(const waypoint* wpt) /*set the time */ if (wpt->creation_time) { /* tm = gmtime(&wpt->creation_time);*/ /* I get the wrong result with gmtime ??? */ - QDate date(wpt->creation_time.date()); - QTime time(wpt->creation_time.time()); + QDate date(wpt->GetCreationTime().date()); + QTime time(wpt->GetCreationTime().time()); pWptHxTmp->time = (time.hour() * 3600) + (time.minute()* 60) + time.second(); pWptHxTmp->date.day = date.day(); pWptHxTmp->date.month = date.month(); diff --git a/gpsbabel/hsa_ndv.cc b/gpsbabel/hsa_ndv.cc index 11b7bd748..7aef17962 100644 --- a/gpsbabel/hsa_ndv.cc +++ b/gpsbabel/hsa_ndv.cc @@ -129,7 +129,7 @@ hsa_ndv_end(void* data, const XML_Char* xml_el) } else if (strcmp(el, "Longitude") == 0) { wpt_tmp->longitude = atof(cdatastr); } else if (strcmp(el, "Time") == 0) { - wpt_tmp->creation_time = atoi(cdatastr); + wpt_tmp->SetCreationTime(atoi(cdatastr)); } } } diff --git a/gpsbabel/html.cc b/gpsbabel/html.cc index c0764471d..42c6f7c9d 100644 --- a/gpsbabel/html.cc +++ b/gpsbabel/html.cc @@ -81,7 +81,7 @@ html_disp(const waypoint* wpt) { char tbuf[1024]; char* cout; - time_t tm = wpt->creation_time; + time_t tm = wpt->GetCreationTime(); gbint32 utmz; double utme, utmn; char utmzc; diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index 464b46306..88bc0ae34 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -269,7 +269,7 @@ humminbird_read_wpt(gbfile* fin) wpt = waypt_new(); wpt->shortname = xstrndup(w.name, sizeof(w.name)); - wpt->creation_time = w.time; + wpt->SetCreationTime(w.time); guder = gudermannian_i1924(w.north); wpt->latitude = geocentric_to_geodetic_hwr(guder); @@ -437,7 +437,7 @@ humminbird_read_track(gbfile* fin) /* Unless it's zero. Sometimes happens, possibly if the gps didn't have a lock when the track was saved. */ - wpt->creation_time = th.time; + wpt->SetCreationTime(th.time); } track_add_wpt(trk, wpt); } @@ -554,7 +554,7 @@ humminbird_read_track_old(gbfile* fin) /* Unless it's zero. Sometimes happens, possibly if the gps didn't have a lock when the track was saved. */ - wpt->creation_time = th.time; + wpt->SetCreationTime(th.time); } track_add_wpt(trk, wpt); } @@ -681,7 +681,7 @@ humminbird_write_waypoint(const waypoint* wpt) hum.depth = si_round(WAYPT_GET(wpt, depth, 0)*100.0); be_write16(&hum.depth, hum.depth); - be_write32(&hum.time, wpt->creation_time); + be_write32(&hum.time, wpt->GetCreationTime()); east = wpt->longitude / 180.0 * EAST_SCALE; be_write32(&hum.east, si_round((east))); @@ -782,7 +782,7 @@ humminbird_track_cb(const waypoint* wpt) north = si_round(inverse_gudermannian_i1924(lat)); if (wpt->creation_time != 0) { - last_time = wpt->creation_time; + last_time = wpt->GetCreationTime(); } if (i == 0) { diff --git a/gpsbabel/igc.cc b/gpsbabel/igc.cc index 6357e22de..52375aecf 100644 --- a/gpsbabel/igc.cc +++ b/gpsbabel/igc.cc @@ -206,7 +206,7 @@ static void igc_task_rec(const char* rec) wpt->longitude = ('E' == lon_hemi[0] ? 1 : -1) * (lon_deg + (lon_min * 1000 + lon_frac) / 1000.0 / 60); - wpt->creation_time = creation; + wpt->SetCreationTime(creation); wpt->description = xstrdup(tmp_str); // Name the waypoint according to the order of the task record @@ -364,7 +364,7 @@ static void data_read(void) date += 24 * 60 * 60; } prev_tod = tod; - pres_wpt->creation_time = date + tod; + pres_wpt->SetCreationTime(date + tod); // Add the waypoint to the pressure altitude track if (pres_alt) { @@ -582,7 +582,7 @@ static void wr_header(void) } // Date in header record is that of the first fix record date = !track ? current_time() : - ((waypoint*) QUEUE_FIRST(&track->waypoint_list))->creation_time; + ((waypoint*) QUEUE_FIRST(&track->waypoint_list))->GetCreationTime(); if (NULL == (tm = gmtime(&date))) { fatal(MYNAME ": Bad track timestamp\n"); @@ -648,7 +648,7 @@ static void wr_task_hdr(const route_head* rte) fatal(MYNAME ": Too much waypoints (more than 99) in task route.\n"); } // Gather data to write to the task identification (first) record - rte_time = wpt->creation_time ? wpt->creation_time : current_time(); + rte_time = wpt->GetCreationTime() ? wpt->GetCreationTime() : current_time(); if (NULL == (tm = gmtime(&rte_time))) { fatal(MYNAME ": Bad task route timestamp\n"); } @@ -692,7 +692,7 @@ static void wr_fix_record(const waypoint* wpt, int pres_alt, int gnss_alt) { struct tm* tm; - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = gmtime(&tt); if (NULL == tm) { @@ -742,7 +742,7 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss return 0; } } while (alt_diff > -10.0); - pres_time = ((waypoint*) elem->next)->creation_time; + pres_time = ((waypoint*) elem->next)->GetCreationTime(); if (global_opts.debug_level >= 1) { printf(MYNAME ": pressure landing time %s", ctime(&pres_time)); } @@ -758,7 +758,7 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss return 0; } // Get a crude indication of groundspeed from the change in lat/lon - time_diff = wpt->creation_time - ((waypoint*) elem)->creation_time; + time_diff = wpt->GetCreationTime() - ((waypoint*) elem)->GetCreationTime(); speed = !time_diff ? 0 : (fabs(wpt->latitude - ((waypoint*) elem)->latitude) + fabs(wpt->longitude - ((waypoint*) elem)->longitude)) / time_diff; @@ -766,7 +766,7 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss printf(MYNAME ": speed=%f\n", speed); } } while (speed < 0.00003); - gnss_time = ((waypoint*) elem->next)->creation_time; + gnss_time = ((waypoint*) elem->next)->GetCreationTime(); if (global_opts.debug_level >= 1) { printf(MYNAME ": gnss landing time %s", ctime(&gnss_time)); } @@ -797,7 +797,7 @@ static double interpolate_alt(const route_head* track, time_t time) curr_elem = prev_elem = QUEUE_FIRST(&track->waypoint_list); } // Find the track points either side of the requested time - while (((waypoint*) curr_elem)->creation_time < time) { + while (((waypoint*) curr_elem)->GetCreationTime() < time) { if (QUEUE_LAST(&track->waypoint_list) == curr_elem) { // Requested time later than all track points, we can't interpolate return unknown_alt; @@ -810,7 +810,7 @@ static double interpolate_alt(const route_head* track, time_t time) curr_wpt = (waypoint*) curr_elem; if (QUEUE_FIRST(&track->waypoint_list) == curr_elem) { - if (curr_wpt->creation_time == time) { + if (curr_wpt->GetCreationTime() == time) { // First point's creation time is an exact match so use it's altitude return curr_wpt->altitude; } else { @@ -819,12 +819,12 @@ static double interpolate_alt(const route_head* track, time_t time) } } // Interpolate - if (0 == (time_diff = curr_wpt->creation_time - prev_wpt->creation_time)) { + if (0 == (time_diff = curr_wpt->GetCreationTime() - prev_wpt->GetCreationTime())) { // Avoid divide by zero return curr_wpt->altitude; } alt_diff = curr_wpt->altitude - prev_wpt->altitude; - return prev_wpt->altitude + (alt_diff / time_diff) * (time - prev_wpt->creation_time); + return prev_wpt->altitude + (alt_diff / time_diff) * (time - prev_wpt->GetCreationTime()); } /* @@ -861,7 +861,7 @@ static void wr_track(void) // Iterate through waypoints in both tracks simultaneously QUEUE_FOR_EACH(&gnss_track->waypoint_list, elem, tmp) { wpt = (waypoint*) elem; - pres_alt = interpolate_alt(pres_track, wpt->creation_time + time_adj); + pres_alt = interpolate_alt(pres_track, wpt->GetCreationTime() + time_adj); wr_fix_record(wpt, (int) pres_alt, (int) wpt->altitude); } } else { diff --git a/gpsbabel/igo8.cc b/gpsbabel/igo8.cc index 61c72bbdb..726830bdc 100644 --- a/gpsbabel/igo8.cc +++ b/gpsbabel/igo8.cc @@ -219,7 +219,7 @@ static void write_igo8_track_point(const waypoint* wpt) if (wpt->creation_time == 0) { le_write32(&point.unix_time, invented_time++); } else { - le_write32(&point.unix_time, wpt->creation_time); + le_write32(&point.unix_time, wpt->GetCreationTime()); } // Write the first part of the Information Block, the start time diff --git a/gpsbabel/jtr.cc b/gpsbabel/jtr.cc index 76bd3be09..70f848374 100644 --- a/gpsbabel/jtr.cc +++ b/gpsbabel/jtr.cc @@ -219,8 +219,7 @@ jtr_read(void) wpt->latitude = lat; wpt->longitude = lon; - wpt->creation_time = time; - wpt->microseconds = micros; + wpt->SetCreationTime(time, micros); if (speed >= 0) { WAYPT_SET(wpt, speed, speed); } @@ -275,7 +274,7 @@ jtr_trkpt_disp_cb(const waypoint* wpt) struct tm tm; if (wpt->creation_time > 0) { - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = *gmtime(&tt); tm.tm_year += 1900; diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index f61aee3bd..1bd895ec6 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -81,8 +81,8 @@ typedef enum { static int realtime_positioning; static bounds kml_bounds; -static time_t kml_time_min; -static time_t kml_time_max; +static gpsbabel::DateTime kml_time_min; +static gpsbabel::DateTime kml_time_max; #define AUTOFORMATTING_OFF(AF) bool AF=writer->autoFormatting(); writer->setAutoFormatting(false); #define AUTOFORMATTING_RESTORE(AF) writer->setAutoFormatting(af); @@ -605,16 +605,13 @@ static void kml_write_bitmap_style(kml_point_type pt_type, const char* bitmap, static void kml_output_timestamp(const waypoint* waypointp) { - if (waypointp->creation_time) { - char time_string[64]; - xml_fill_in_time(time_string, waypointp->creation_time, waypointp->microseconds, XML_LONG_TIME); - if (time_string[0]) { - writer->writeStartElement("TimeStamp"); - AUTOFORMATTING_OFF(af); // FIXME: we turn off autoformatting just to match old writer test references. - writer->writeTextElement("when", time_string); - writer->writeEndElement(); // Close TimeStamp tag - AUTOFORMATTING_RESTORE(af); - } + QString time_string = waypointp->CreationTimeXML(); + if(!time_string.isEmpty()) { + writer->writeStartElement("TimeStamp"); + AUTOFORMATTING_OFF(af); // FIXME: we turn off autoformatting just to match old writer test references. + writer->writeTextElement("when", time_string); + writer->writeEndElement(); // Close TimeStamp tag + AUTOFORMATTING_RESTORE(af); } } @@ -717,9 +714,9 @@ void kml_output_trkdescription(const route_head* header, computed_trkdata* td) if (td->start && td->end) { char time_string[64]; - xml_fill_in_time(time_string, td->start, 0, XML_LONG_TIME); + xml_fill_in_time(time_string, td->start, XML_LONG_TIME); kml_td(hwriter, "Start Time", QString(" %1 ").arg(time_string)); - xml_fill_in_time(time_string, td->end, 0, XML_LONG_TIME); + xml_fill_in_time(time_string, td->end, XML_LONG_TIME); kml_td(hwriter, "End Time", QString(" %1 ").arg(time_string)); } @@ -735,9 +732,9 @@ void kml_output_trkdescription(const route_head* header, computed_trkdata* td) if (td->start && td->end) { char time_string[64]; writer->writeStartElement("TimeSpan"); - xml_fill_in_time(time_string, td->start, 0, XML_LONG_TIME); + xml_fill_in_time(time_string, td->start, XML_LONG_TIME); writer->writeTextElement("begin", time_string); - xml_fill_in_time(time_string, td->end, 0, XML_LONG_TIME); + xml_fill_in_time(time_string, td->end, XML_LONG_TIME); writer->writeTextElement("end", time_string); writer->writeEndElement(); // Close TimeSpan tag } @@ -864,13 +861,10 @@ static void kml_output_description(const waypoint* pt) /* This really shouldn't be here, but as of this writing, * Earth can't edit/display the TimeStamp. */ - if (pt->creation_time) { - char time_string[64]; - - xml_fill_in_time(time_string, pt->creation_time, - pt->microseconds, XML_LONG_TIME); - if (time_string[0]) { - kml_td(hwriter, QString("Time: %1 ").arg(time_string)); + if (pt->GetCreationTime()) { + QString time_string = pt->CreationTimeXML(); + if(!time_string.isEmpty()) { + kml_td(hwriter, QString("Time: %1 ").arg(time_string)); } } @@ -883,13 +877,13 @@ static void kml_output_description(const waypoint* pt) static void kml_recompute_time_bounds(const waypoint* waypointp) { - if (waypointp->creation_time && (waypointp->creation_time < kml_time_min)) { - kml_time_min = waypointp->creation_time; + if (waypointp->GetCreationTime() && (waypointp->GetCreationTime() < kml_time_min)) { + kml_time_min = waypointp->GetCreationTime(); } - if (waypointp->creation_time > kml_time_max) { - kml_time_max = waypointp->creation_time; + if (waypointp->GetCreationTime() > kml_time_max) { + kml_time_max = waypointp->GetCreationTime(); if (kml_time_min == 0) { - kml_time_min = waypointp->creation_time; + kml_time_min = waypointp->GetCreationTime(); } } } @@ -1459,7 +1453,7 @@ static void kml_geocache_pr(const waypoint* waypointp) kml_output_timestamp(waypointp); if (waypointp->creation_time) { strcpy(date_placed, - qPrintable(waypointp->creation_time.toString("dd-MMM-yyyy"))); + qPrintable(waypointp->GetCreationTime().toString("dd-MMM-yyyy"))); } else { date_placed[0] = '\0'; } @@ -1736,13 +1730,9 @@ static void kml_mt_hdr(const route_head* header) QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) { waypoint* tpt = (waypoint*)elem; - if (tpt->creation_time) { - char time_string[64]; - xml_fill_in_time(time_string, tpt->creation_time, tpt->microseconds, - XML_LONG_TIME); - if (time_string[0]) { - writer->writeTextElement("when", time_string); - } + if (tpt->GetCreationTime()) { + QString time_string = tpt->CreationTimeXML(); + writer->writeOptionalTextElement("when", time_string); } else { writer->writeStartElement("when"); writer->writeEndElement(); // Close when tag @@ -1862,7 +1852,7 @@ void kml_write_AbstractView(void) writer->writeStartElement("gx:TimeSpan"); if (kml_time_min) { char time_string[64]; - xml_fill_in_time(time_string, kml_time_min, 0, XML_LONG_TIME); + xml_fill_in_time(time_string, kml_time_min, XML_LONG_TIME); if (time_string[0]) { writer->writeTextElement("begin", time_string); } @@ -1878,7 +1868,7 @@ void kml_write_AbstractView(void) // ensure the right edge of that time slider includes us. // time_max = realtime_positioning ? kml_time_max + 600 : kml_time_max; - xml_fill_in_time(time_string, time_max, 0, XML_LONG_TIME); + xml_fill_in_time(time_string, time_max, XML_LONG_TIME); if (time_string[0]) { writer->writeTextElement("end", time_string); } @@ -2104,7 +2094,7 @@ static route_head* posn_trk_head = NULL; static void kml_wr_position(waypoint* wpt) { - static time_t last_valid_fix; + static gpsbabel::DateTime last_valid_fix; kml_wr_init(posnfilenametmp); @@ -2136,10 +2126,10 @@ kml_wr_position(waypoint* wpt) case fix_unknown: break; default: - last_valid_fix = wpt->creation_time; + last_valid_fix = wpt->GetCreationTime(); } - wpt->icon_descr = kml_get_posn_icon(wpt->creation_time - last_valid_fix); + wpt->icon_descr = kml_get_posn_icon(wpt->GetCreationTime() - last_valid_fix); /* In order to avoid clutter while we're sitting still, don't add diff --git a/gpsbabel/magproto.cc b/gpsbabel/magproto.cc index 7b56c3b5c..984922bb9 100644 --- a/gpsbabel/magproto.cc +++ b/gpsbabel/magproto.cc @@ -993,8 +993,7 @@ mag_trkparse(char* trkmsg) dmy = dmy / 100; tm.tm_mday = dmy % 100; - waypt->creation_time = mkgmtime(&tm); - waypt->microseconds = CENTI_TO_MICRO(fracsecs); + waypt->SetCreationTime(mkgmtime(&tm), CENTI_TO_MICRO(fracsecs)); if (latdir == 'S') { latdeg = -latdeg; @@ -1443,7 +1442,7 @@ void mag_track_disp(const waypoint* waypointp) ilon = waypointp->longitude; tm = NULL; if (waypointp->creation_time) { - const time_t ct = waypointp->creation_time; + const time_t ct = waypointp->GetCreationTime(); tm = gmtime(&ct); if (tm) { hms = tm->tm_hour * 10000 + tm->tm_min * 100 + diff --git a/gpsbabel/mapsend.cc b/gpsbabel/mapsend.cc index 31d18d7d9..8ae4e2e03 100644 --- a/gpsbabel/mapsend.cc +++ b/gpsbabel/mapsend.cc @@ -233,7 +233,8 @@ static void mapsend_read(void) { mapsend_hdr hdr; - int type, len; + int type; + gbsize_t len; char buf[3]; /* @@ -471,7 +472,7 @@ void mapsend_track_hdr(const route_head* trk) void mapsend_track_disp(const waypoint* wpt) { unsigned char c; - int t; + gbint32 t; static int last_time; /* @@ -484,7 +485,7 @@ void mapsend_track_disp(const waypoint* wpt) * * This is rumoured (but yet unconfirmed) to be fixed in f/w 5.12. */ - t = wpt->creation_time; + t = wpt->GetCreationTime(); if (t < last_time) { t = last_time; } diff --git a/gpsbabel/mapsource.cc b/gpsbabel/mapsource.cc index 690bf342d..3d10c591a 100644 --- a/gpsbabel/mapsource.cc +++ b/gpsbabel/mapsource.cc @@ -1148,7 +1148,7 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { testwpt = (waypoint*)elem; if (rte_datapoints == 0) { - uniqueValue = testwpt->creation_time; + uniqueValue = testwpt->GetCreationTime(); } if (testwpt->latitude > maxlat) { maxlat = testwpt->latitude; @@ -1544,8 +1544,7 @@ mps_track_r(gbfile* mps_file, int mps_ver, route_head** trk) thisWaypoint = waypt_new(); thisWaypoint->latitude = GPS_Math_Semi_To_Deg(lat); thisWaypoint->longitude = GPS_Math_Semi_To_Deg(lon); - thisWaypoint->creation_time = dateTime; - thisWaypoint->microseconds = 0; + thisWaypoint->SetCreationTime(dateTime); thisWaypoint->altitude = mps_altitude; if (mps_depth != unknown_alt) { WAYPT_SET(thisWaypoint, depth, mps_depth); @@ -1582,7 +1581,7 @@ mps_trackhdr_w(gbfile* mps_file, int mps_ver, const route_head* trk) QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { if (trk_datapoints == 0) { testwpt = (waypoint*)elem; - uniqueValue = testwpt->creation_time; + uniqueValue = testwpt->GetCreationTime(); } trk_datapoints++; } @@ -1637,7 +1636,7 @@ static void mps_trackdatapoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt) { int lat, lon; - time_t t = wpt->creation_time; + time_t t = wpt->GetCreationTime(); char zbuf[10]; double mps_altitude = wpt->altitude; diff --git a/gpsbabel/mmo.cc b/gpsbabel/mmo.cc index 761938f8e..cf91d906e 100644 --- a/gpsbabel/mmo.cc +++ b/gpsbabel/mmo.cc @@ -491,7 +491,7 @@ mmo_read_CObjWaypoint(mmo_data_t* data) time = data->ctime; } if (time > 0) { - wpt->creation_time = time; + wpt->SetCreationTime(time); } if (mmo_version >= 0x18) { @@ -726,7 +726,7 @@ mmo_read_CObjTrack(mmo_data_t* data) unk = gbfgetc(fin); DBG((sobj, "Unknown = 0x%02X (%d)\n", unk, unk)); - wpt->creation_time = gbfgetint32(fin); + wpt->SetCreationTime(gbfgetint32(fin)); wpt->altitude = gbfgetflt(fin); if (unk != 0) { diff --git a/gpsbabel/mtk_locus.cc b/gpsbabel/mtk_locus.cc index 15efd00f1..e977538a2 100644 --- a/gpsbabel/mtk_locus.cc +++ b/gpsbabel/mtk_locus.cc @@ -437,8 +437,7 @@ process_pmtklox() if (global_opts.masked_objective & TRKDATAMASK) { trkpt = waypt_new(); - trkpt->creation_time = timestamp; - trkpt->microseconds = 0; + trkpt->SetCreationTime(timestamp); trkpt->latitude = latitude; trkpt->longitude = longitude; trkpt->altitude = height; @@ -450,8 +449,7 @@ process_pmtklox() if (global_opts.masked_objective & WPTDATAMASK) { waypt = waypt_new(); - waypt->creation_time = timestamp; - waypt->microseconds = 0; + waypt->SetCreationTime(timestamp); waypt->latitude = latitude; waypt->longitude = longitude; waypt->altitude = height; diff --git a/gpsbabel/navicache.cc b/gpsbabel/navicache.cc index 848f999d7..f530b5678 100644 --- a/gpsbabel/navicache.cc +++ b/gpsbabel/navicache.cc @@ -177,7 +177,7 @@ nav_start(void* data, const XML_Char* xml_el, const XML_Char** xml_attr) tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; - wpt_tmp->creation_time = mktime(&tm); + wpt_tmp->SetCreationTime(mktime(&tm)); } else if (0 == strcmp(ap[0], "retired")) { if (!strcmp(ap[1], "yes") && noretired) { xfree(wpt_tmp); diff --git a/gpsbabel/navilink.cc b/gpsbabel/navilink.cc index a2d1bdc6f..562cd18ed 100644 --- a/gpsbabel/navilink.cc +++ b/gpsbabel/navilink.cc @@ -415,7 +415,7 @@ decode_waypoint(const unsigned char* buffer) decode_position(buffer + 12, waypt); waypt->shortname = xstrdup((char*)buffer + 4); waypt->icon_descr = icon_table[buffer[28]]; - waypt->creation_time = decode_datetime(buffer + 22); + waypt->SetCreationTime(decode_datetime(buffer + 22)); return waypt; } @@ -430,7 +430,7 @@ encode_waypoint(const waypoint* waypt, unsigned char* buffer) buffer[10] = 0; buffer[11] = 0; encode_position(waypt, buffer + 12); - encode_datetime(waypt->creation_time, buffer + 22); + encode_datetime(waypt->GetCreationTime(), buffer + 22); buffer[28] = find_icon_from_descr(waypt->icon_descr); buffer[29] = 0; buffer[30] = 0x00; @@ -443,7 +443,7 @@ decode_trackpoint(const unsigned char* buffer) waypoint* waypt = waypt_new(); decode_position(buffer + 12, waypt); - waypt->creation_time = decode_datetime(buffer + 22); + waypt->SetCreationTime(decode_datetime(buffer + 22)); WAYPT_SET(waypt, course, le_read16(buffer + 2)); WAYPT_SET(waypt, speed, KPH_TO_MPS(buffer[29] * 2)); @@ -465,7 +465,7 @@ encode_trackpoint(const waypoint* waypt, unsigned serial, unsigned char* buffer) le_write32(buffer + 4, x); le_write32(buffer + 8, y); encode_position(waypt, buffer + 12); - encode_datetime(waypt->creation_time, buffer + 22); + encode_datetime(waypt->GetCreationTime(), buffer + 22); buffer[28] = z; buffer[29] = MPS_TO_KPH(WAYPT_GET(waypt, speed, 0) / 2); buffer[30] = 0x5a; @@ -852,7 +852,7 @@ navilink_decode_logpoint(const unsigned char* buffer) waypt->hdop = ((unsigned char)buffer[0]) * 0.2f; waypt->sat = buffer[1]; waypt->microseconds = decode_sbp_usec(buffer + 2); - waypt->creation_time = decode_sbp_datetime_packed(buffer + 4); + waypt->SetCreationTime(decode_sbp_datetime_packed(buffer + 4)); decode_sbp_position(buffer + 12, waypt); WAYPT_SET(waypt, speed, le_read16(buffer + 24) * 0.01f); WAYPT_SET(waypt, course, le_read16(buffer + 26) * 0.01f); diff --git a/gpsbabel/nmea.cc b/gpsbabel/nmea.cc index 1584f4bd7..f939bbf42 100644 --- a/gpsbabel/nmea.cc +++ b/gpsbabel/nmea.cc @@ -899,7 +899,7 @@ nmea_fix_timestamps(route_head* track) wpt->creation_time+=SECONDS_PER_DAY; } } - prev = wpt->creation_time; + prev = wpt->GetCreationTime(); } } } @@ -1261,19 +1261,19 @@ nmea_trackpt_pr(const waypoint* wpt) if (sleepus >= 0) { gb_sleep(sleepus); } else { - long wait_time = wpt->creation_time - last_time; + long wait_time = wpt->GetCreationTime() - last_time; if (wait_time > 0) { gb_sleep(wait_time * 1000000); } } } - last_time = wpt->creation_time; + last_time = wpt->GetCreationTime(); } lat = degrees2ddmm(wpt->latitude); lon = degrees2ddmm(wpt->longitude); - time_t ct = wpt->creation_time; + time_t ct = wpt->GetCreationTime(); tm = gmtime(&ct); if (tm) { hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec; diff --git a/gpsbabel/osm.cc b/gpsbabel/osm.cc index 345dd01d1..ea14f9977 100644 --- a/gpsbabel/osm.cc +++ b/gpsbabel/osm.cc @@ -802,9 +802,8 @@ osm_waypt_disp(const waypoint* wpt) gbfprintf(fout, " latitude, wpt->longitude); if (wpt->creation_time) { - char time_string[64]; - xml_fill_in_time(time_string, wpt->creation_time, wpt->microseconds, XML_LONG_TIME); - gbfprintf(fout, " timestamp='%s'", time_string); + QString time_string = wpt->CreationTimeXML(); + gbfprintf(fout, " timestamp='%s'", qPrintable(time_string)); } gbfprintf(fout, ">\n"); diff --git a/gpsbabel/ozi.cc b/gpsbabel/ozi.cc index dd2304be6..3c39c6b61 100644 --- a/gpsbabel/ozi.cc +++ b/gpsbabel/ozi.cc @@ -166,7 +166,7 @@ ozi_set_time_str(const char *str, waypoint *waypointp) int len; ozi_time = atof(str); - waypointp->creation_time = (ozi_time - DAYS_SINCE_1990) * SECONDS_PER_DAY; + waypointp->SetCreationTime((ozi_time - DAYS_SINCE_1990) * SECONDS_PER_DAY); dot = strchr(str, '.'); /* get number of characters after dot */ diff --git a/gpsbabel/palmdoc.cc b/gpsbabel/palmdoc.cc index 8e3d656cd..6cb77fb94 100644 --- a/gpsbabel/palmdoc.cc +++ b/gpsbabel/palmdoc.cc @@ -405,7 +405,7 @@ palmdoc_disp(const waypoint *wpt) { int latint, lonint; char tbuf[1024]; - time_t tm = wpt->creation_time; + time_t tm = wpt->GetCreationTime(); int32 utmz; double utme, utmn; char utmzc; diff --git a/gpsbabel/pathaway.cc b/gpsbabel/pathaway.cc index 914b75d6f..542816071 100644 --- a/gpsbabel/pathaway.cc +++ b/gpsbabel/pathaway.cc @@ -691,7 +691,7 @@ static void ppdb_write_wpt(const waypoint *wpt) if (wpt->creation_time != 0) { tmp = str_pool_get(20); - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = *gmtime(&tt); strftime(tmp, 20, datefmt, &tm); buff = ppdb_strcat(buff, tmp, NULL, &len); diff --git a/gpsbabel/pcx.cc b/gpsbabel/pcx.cc index 979f21d8c..b4a463d4b 100644 --- a/gpsbabel/pcx.cc +++ b/gpsbabel/pcx.cc @@ -254,7 +254,7 @@ data_read(void) tm.tm_year += 100; } wpt_tmp = waypt_new(); - wpt_tmp->creation_time = mkgmtime(&tm); + wpt_tmp->SetCreationTime(mkgmtime(&tm)); if (read_as_degrees) { wpt_tmp->longitude = lon; wpt_tmp->latitude = lat; @@ -321,7 +321,7 @@ gpsutil_disp(const waypoint *wpt) double lon,lat; int icon_token = 0; char tbuf[1024]; - time_t tm = wpt->creation_time; + time_t tm = wpt->GetCreationTime(); lon = degrees2ddmm(wpt->longitude); lat = degrees2ddmm(wpt->latitude); @@ -407,7 +407,7 @@ pcx_track_disp(const waypoint *wpt) lon = degrees2ddmm(wpt->longitude); lat = degrees2ddmm(wpt->latitude); - const time_t ct = wpt->creation_time; + const time_t ct = wpt->GetCreationTime(); tm = gmtime(&ct); strftime(tbuf, sizeof(tbuf), "%d-%b-%y %H:%M:%S", tm); /* currently ...%T does nothing under Windows */ diff --git a/gpsbabel/pocketfms_bc.cc b/gpsbabel/pocketfms_bc.cc index 76336ce78..652193b9c 100644 --- a/gpsbabel/pocketfms_bc.cc +++ b/gpsbabel/pocketfms_bc.cc @@ -108,7 +108,7 @@ read_tracks(void) wpt->latitude = le_read_float(&bc.latitude); wpt->longitude = le_read_float(&bc.longitude); wpt->altitude = FEET_TO_METERS(le_read_float(&bc.altitude)); - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); wpt->hdop = le_read_float(&bc.ehpe); wpt->vdop = le_read_float(&bc.evpe); wpt->pdop = le_read_float(&bc.espe); @@ -132,10 +132,10 @@ pocketfms_waypt_disp(const waypoint *wpt) struct tm *tm; memset(&bc, 0, sizeof(bc)); - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = localtime(&tt); if (wpt->creation_time) { - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = gmtime(&tt); } diff --git a/gpsbabel/psitrex.cc b/gpsbabel/psitrex.cc index ed119acb8..5fed711a3 100644 --- a/gpsbabel/psitrex.cc +++ b/gpsbabel/psitrex.cc @@ -488,7 +488,7 @@ psit_routehdr_w(gbfile *psit_file, const route_head *rte) QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { testwpt = (waypoint *)elem; if (rte_datapoints == 0) { - uniqueValue = testwpt->creation_time; + uniqueValue = testwpt->GetCreationTime(); } rte_datapoints++; } @@ -597,8 +597,9 @@ psit_track_r(gbfile *psit_file, route_head **trk) if ((strcmp(psit_current_token, "1") == 0) || (track_head == NULL)) { track_head = route_head_alloc(); - /* Add a number to the track name. With Garmins, the "first" tracklog is usually ACTIVE LOG - the second is ACTIVE LOG001 and so on */ + /* Add a number to the track name. With Garmins, the "first" + tracklog is usually ACTIVE LOG + the second is ACTIVE LOG001 and so on */ if (trk_num > 0) { sprintf(tbuf, "%s%03d", trkname, trk_num); track_head->rte_name = xstrdup(tbuf); @@ -608,14 +609,14 @@ psit_track_r(gbfile *psit_file, route_head **trk) trk_num++; track_add_head(track_head); } - - thisWaypoint->creation_time = dateTime; + + thisWaypoint->SetCreationTime(dateTime); track_add_wpt(track_head, thisWaypoint); - + if (gbfeof(psit_file)) { break; } - + psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), wscomma); } else { break; @@ -647,7 +648,7 @@ psit_trackhdr_w(gbfile *psit_file, const route_head *trk) QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { if (trk_datapoints == 0) { testwpt = (waypoint *)elem; - uniqueValue = testwpt->creation_time; + uniqueValue = testwpt->GetCreationTime(); } trk_datapoints++; } @@ -691,7 +692,7 @@ psit_trackhdr_w_wrapper(const route_head *trk) static void psit_trackdatapoint_w(gbfile *psit_file, const waypoint *wpt) { - time_t t = wpt->creation_time; + time_t t = wpt->GetCreationTime(); struct tm *tmTime = gmtime(&t); gbfprintf(psit_file, "%11.6f,%11.6f,", @@ -808,7 +809,8 @@ psit_write(void) route_disp_all(psit_routehdr_w_wrapper, psit_noop, psit_waypoint_w_wrapper); } if (global_opts.objective == trkdata) { - track_disp_all(psit_trackhdr_w_wrapper, psit_noop, psit_trackdatapoint_w_wrapper); + track_disp_all(psit_trackhdr_w_wrapper, + psit_noop, psit_trackdatapoint_w_wrapper); } mkshort_del_handle(&mkshort_handle); diff --git a/gpsbabel/raymarine.cc b/gpsbabel/raymarine.cc index 8d08f5339..830397679 100644 --- a/gpsbabel/raymarine.cc +++ b/gpsbabel/raymarine.cc @@ -218,7 +218,7 @@ raymarine_read(void) wpt->notes = xstrdup(str); } if (((str = inifile_readstr(fin, sect, "Time"))) && *str) { - wpt->creation_time = EXCEL_TO_TIMET(atof(str)); + wpt->SetCreationTime(EXCEL_TO_TIMET(atof(str))); } if (((str = inifile_readstr(fin, sect, "Bmp"))) && *str) { unsigned int symbol = atoi(str); @@ -349,7 +349,7 @@ write_waypoint(gbfile *fout, const waypoint *wpt, const int waypt_no, const char } } notes = csv_stringclean(notes, LINE_FEED); - time = (wpt->creation_time > 0) ? TIMET_TO_EXCEL(wpt->creation_time) : TIMET_TO_EXCEL(gpsbabel_time); + time = (wpt->creation_time > 0) ? TIMET_TO_EXCEL(wpt->GetCreationTime()) : TIMET_TO_EXCEL(gpsbabel_time); name = (char *)wpt->extra_data; gbfprintf(fout, "[Wp%d]" LINE_FEED diff --git a/gpsbabel/route.cc b/gpsbabel/route.cc index 8761413a5..607f74c3c 100644 --- a/gpsbabel/route.cc +++ b/gpsbabel/route.cc @@ -582,7 +582,7 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) double tlat, tlon, plat, plon, dist; thisw = (waypoint *)elem; - timed = thisw->creation_time - prev->creation_time; + timed = thisw->GetCreationTime() - prev->GetCreationTime(); /* * gcdist and heading want radians, not degrees. @@ -651,12 +651,12 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) tdata->max_cad = (int) thisw->cadence; } - if (thisw->creation_time && (thisw->creation_time < tdata->start)) { - tdata->start = thisw->creation_time; + if (thisw->GetCreationTime() && (thisw->GetCreationTime() < tdata->start)) { + tdata->start = thisw->GetCreationTime(); } if (thisw->creation_time > tdata->end) { - tdata->end = thisw->creation_time; + tdata->end = thisw->GetCreationTime(); if (tdata->start == 0) { tdata->start = tdata->end; } diff --git a/gpsbabel/saroute.cc b/gpsbabel/saroute.cc index f8e6205e8..3b01f4571 100644 --- a/gpsbabel/saroute.cc +++ b/gpsbabel/saroute.cc @@ -381,12 +381,11 @@ my_read(void) if (totaldist > seglen) { totaldist = seglen; } - wpt_tmp->creation_time = + wpt_tmp->SetCreationTime( gpsbabel_time+starttime+ - transittime * totaldist/seglen; + transittime * totaldist/seglen); } else { - wpt_tmp->creation_time = - gpsbabel_time+starttime; + wpt_tmp->SetCreationTime(gpsbabel_time+starttime); totaldist = 0; } oldlat = lat; diff --git a/gpsbabel/sbn.cc b/gpsbabel/sbn.cc index ffd5c0319..7d57a21c2 100644 --- a/gpsbabel/sbn.cc +++ b/gpsbabel/sbn.cc @@ -225,7 +225,7 @@ decode_sbn_datetime(const unsigned char *buffer, waypoint *waypt) tm.tm_mon = buffer[2] - 1; tm.tm_year = be_readu16(buffer) - 1900; - waypt->creation_time = mkgmtime(&tm); + waypt->SetCreationTime(mkgmtime(&tm)); waypt->microseconds = (ms % 1000) * 1000; } diff --git a/gpsbabel/skyforce.cc b/gpsbabel/skyforce.cc index 105886148..a78332233 100644 --- a/gpsbabel/skyforce.cc +++ b/gpsbabel/skyforce.cc @@ -113,7 +113,7 @@ skyforce_parse_trk(const char *str) fatal(MYNAME ": Could not parse date string (%s - %s).\n", buf, cx); } - wpt->creation_time = mkgmtime(&tm); + wpt->SetCreationTime(mkgmtime(&tm)); len = strlen(str); @@ -177,7 +177,7 @@ skyforce_waypt_disp_cb(const waypoint *wpt) if (global_opts.objective == trkdata) { struct tm tm; - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = *gmtime(&tt); strftime(buf + 2, sizeof(buf) - 2, "%d%m%y %H%M%S ", &tm); } else { diff --git a/gpsbabel/skytraq.cc b/gpsbabel/skytraq.cc index 9b6a71579..f9ed3e480 100644 --- a/gpsbabel/skytraq.cc +++ b/gpsbabel/skytraq.cc @@ -663,7 +663,7 @@ make_trackpoint(struct read_state *st, double lat, double lon, double alt) wpt->latitude = lat; wpt->longitude = lon; wpt->altitude = alt; - wpt->creation_time = gpstime_to_timet(st->gps_week, st->gps_sec); + wpt->SetCreationTime(gpstime_to_timet(st->gps_week, st->gps_sec)); return wpt; } diff --git a/gpsbabel/smplrout.cc b/gpsbabel/smplrout.cc index 137e5e76a..e0d49cd6f 100644 --- a/gpsbabel/smplrout.cc +++ b/gpsbabel/smplrout.cc @@ -186,9 +186,9 @@ compute_xte(struct xte *xte_rec) fatal(MYNAME ": relative needs hdop information.\n"); } // if timestamps exist, distance to interpolated point - if (wpt1->creation_time != wpt2->creation_time) { + if (wpt1->GetCreationTime() != wpt2->GetCreationTime()) { frac = (double)(wpt3->creation_time - wpt1->creation_time) / - (wpt2->creation_time - wpt1->creation_time); + (wpt2->GetCreationTime() - wpt1->GetCreationTime()); linepart(wpt1->latitude, wpt1->longitude, wpt2->latitude, wpt2->longitude, frac, &reslat, &reslon); diff --git a/gpsbabel/sort.cc b/gpsbabel/sort.cc index b3c526340..d13c67da7 100644 --- a/gpsbabel/sort.cc +++ b/gpsbabel/sort.cc @@ -70,7 +70,7 @@ sort_comp(const queue * a, const queue * b) case sm_description: return strcmp(x1->description, x2->description); case sm_time: - return x1->creation_time - x2->creation_time; + return x1->GetCreationTime() - x2->GetCreationTime(); default: abort(); return 0; /* Internal caller error. */ diff --git a/gpsbabel/src/core/datetime.h b/gpsbabel/src/core/datetime.h index 0270ba819..4456d18d4 100644 --- a/gpsbabel/src/core/datetime.h +++ b/gpsbabel/src/core/datetime.h @@ -85,6 +85,9 @@ public: void addUSecs(qint64 usecs) const { this->addMSecs(usecs / 1000); } + int usec() const { + return this->time().msec() * 1000; + } // Integer form: YYMMDD int ymd() const { diff --git a/gpsbabel/stmsdf.cc b/gpsbabel/stmsdf.cc index b2e548d5e..6534565bb 100644 --- a/gpsbabel/stmsdf.cc +++ b/gpsbabel/stmsdf.cc @@ -169,7 +169,7 @@ track_qsort_cb(const void *a, const void *b) const waypoint *wa = *(waypoint **)a; const waypoint *wb = *(waypoint **)b; - return wa->creation_time - wb->creation_time; + return wa->GetCreationTime() - wb->GetCreationTime(); } static void @@ -330,7 +330,7 @@ parse_point(char *line) tm.tm_min = min; tm.tm_sec = sec; - wpt->creation_time = mklocaltime(&tm); + wpt->SetCreationTime(mklocaltime(&tm)); } if (datum != DATUM_WGS84) { @@ -455,7 +455,7 @@ calculate(const waypoint *wpt, double *dist, double *speed, double *course, *dist = 0; /* calc. diffs on 32- and 64-bit hosts */ } - time = wpt->creation_time - trkpt_out->creation_time; + time = wpt->creation_time - trkpt_out->GetCreationTime(); if (time == 0) { *speed = 0; } else { @@ -526,7 +526,7 @@ any_waypt_calc_cb(const waypoint *wpt) } if ((all_points == 0) && (this_points == 0)) { - start_time = wpt->creation_time; + start_time = wpt->GetCreationTime(); } this_points++; @@ -544,7 +544,7 @@ any_waypt_calc_cb(const waypoint *wpt) this_distance = this_distance + dist; if (trkpt_out != NULL) { - this_time += (wpt->creation_time - trkpt_out->creation_time); + this_time += (wpt->GetCreationTime() - trkpt_out->GetCreationTime()); } trkpt_out = (waypoint *)wpt; @@ -585,7 +585,7 @@ track_disp_wpt_cb(const waypoint *wpt) track_points++; all_track_points++; - time_t ct = wpt->creation_time; + time_t ct = wpt->GetCreationTime(); tm = *localtime(&ct); strftime(tbuf, sizeof(tbuf), "%d.%m.%Y,%H:%M.%S", &tm); @@ -669,8 +669,8 @@ route_disp_wpt_cb(const waypoint *wpt) static void track_disp_custom_cb(const waypoint *wpt) { - if (wpt->creation_time && (wpt->altitude != unknown_alt)) { - gbfprintf(fout, "%d,%.f\n", (int)(wpt->creation_time - start_time), wpt->altitude); + if (wpt->GetCreationTime() && (wpt->altitude != unknown_alt)) { + gbfprintf(fout, "%d,%.f\n", (int)(wpt->GetCreationTime() - start_time), wpt->altitude); } } diff --git a/gpsbabel/stmwpp.cc b/gpsbabel/stmwpp.cc index d50b9a6cf..8d627352d 100644 --- a/gpsbabel/stmwpp.cc +++ b/gpsbabel/stmwpp.cc @@ -166,7 +166,7 @@ stmwpp_data_read(void) if (wpt != NULL) { time.tm_year -= 1900; time.tm_mon--; - wpt->creation_time = mkgmtime(&time); + wpt->SetCreationTime(mkgmtime(&time)); switch (what) { case STM_WAYPT: @@ -239,7 +239,7 @@ stmwpp_waypt_cb(const waypoint *wpt) return; } - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = *gmtime(&tt); tm.tm_year += 1900; tm.tm_mon++; diff --git a/gpsbabel/subrip.cc b/gpsbabel/subrip.cc index 40f2c83ff..dd48e2caf 100644 --- a/gpsbabel/subrip.cc +++ b/gpsbabel/subrip.cc @@ -92,17 +92,17 @@ subrip_prevwp_pr(const waypoint *waypointp) time_t starttime; time_t endtime; - if (prevwpp->creation_time >= time_offset) + if (prevwpp->GetCreationTime() >= time_offset) /* if this condition is not true, the waypoint is before the beginning of * the video and will be ignored */ { - starttime = gps_to_video_time(prevwpp->creation_time); + starttime = gps_to_video_time(prevwpp->GetCreationTime()); if (!waypointp) { endtime = starttime + 1; } else { - endtime = gps_to_video_time(waypointp->creation_time); + endtime = gps_to_video_time(waypointp->GetCreationTime()); } gbfprintf(fout, "%d\n", stnum); stnum++; @@ -120,7 +120,7 @@ subrip_prevwp_pr(const waypoint *waypointp) } else if WAYPT_HAS(prevwpp, speed) { gbfprintf(fout, "\n"); } - subrip_write_time(prevwpp->creation_time); + subrip_write_time(prevwpp->GetCreationTime()); gbfprintf(fout, " Lat=%0.5lf Lon=%0.5lf\n", prevwpp->latitude + .000005, prevwpp->longitude + .000005); @@ -148,7 +148,7 @@ subrip_trkpt_pr(const waypoint *waypointp) * way of solving this should be trivial to you :-) */ { - time_offset = sync_time(waypointp->creation_time, opt_videotime); + time_offset = sync_time(waypointp->GetCreationTime(), opt_videotime); } if (prevwpp) { diff --git a/gpsbabel/text.cc b/gpsbabel/text.cc index ef2cd59c1..5eb127a9a 100644 --- a/gpsbabel/text.cc +++ b/gpsbabel/text.cc @@ -97,7 +97,7 @@ text_disp(const waypoint *wpt) { int latint, lonint; char tbuf[1024]; - time_t tm = wpt->creation_time; + time_t tm = wpt->GetCreationTime(); gbint32 utmz; double utme, utmn; char utmzc; diff --git a/gpsbabel/tiger.cc b/gpsbabel/tiger.cc index 8749c1ffe..b39c836cd 100644 --- a/gpsbabel/tiger.cc +++ b/gpsbabel/tiger.cc @@ -189,7 +189,7 @@ tiger_disp(const waypoint *wpt) pin = wpt->icon_descr; } else if (wpt->icon_descr.contains("-unfound")) { pin = unfoundmarker; - } else if (wpt->creation_time > current_time() - 3600 * 24 * thresh_days) { + } else if (wpt->GetCreationTime() > current_time() - 3600 * 24 * thresh_days) { pin = newmarker; } else { pin = oldmarker; diff --git a/gpsbabel/trackfilter.cc b/gpsbabel/trackfilter.cc index 5bcdfcc01..f8c0a01c6 100644 --- a/gpsbabel/trackfilter.cc +++ b/gpsbabel/trackfilter.cc @@ -269,7 +269,7 @@ trackfilter_merge_qsort_cb(const void *a, const void *b) const waypoint *wa = *(waypoint **)a; const waypoint *wb = *(waypoint **)b; - return wa->creation_time - wb->creation_time; + return wa->GetCreationTime() - wb->GetCreationTime(); } static fix_type @@ -344,17 +344,16 @@ trackfilter_fill_track_list_cb(const route_head *track) /* callback for track_d i++; if (i == 1) { - track_list[track_ct].first_time = wpt->creation_time; + track_list[track_ct].first_time = wpt->GetCreationTime(); } else if (i == track->rte_waypt_ct) { - track_list[track_ct].last_time = wpt->creation_time; + track_list[track_ct].last_time = wpt->GetCreationTime(); } - if ((need_time != 0) && (prev != NULL) && (prev->creation_time > wpt->creation_time)) { + if ((need_time != 0) && (prev != NULL) && (prev->GetCreationTime() > wpt->GetCreationTime())) { if (opt_merge == NULL) { - char t1[64], t2[64]; - xml_fill_in_time(t1, prev->creation_time, 0, XML_LONG_TIME); - xml_fill_in_time(t2, wpt->creation_time, 0, XML_LONG_TIME); - fatal(MYNAME "-init: Track points badly ordered (timestamp %s > %s)!\n", t1, t2); + QString t1 = prev->CreationTimeXML(); + QString t2 = wpt->CreationTimeXML(); + fatal(MYNAME "-init: Track points badly ordered (timestamp %s > %s)!\n", qPrintable(t1), qPrintable(t2)); } } prev = wpt; @@ -525,7 +524,7 @@ trackfilter_merge(void) for (i = 0; i < track_pts-timeless_pts; i++) { wpt = buff[i]; - if ((prev == NULL) || (prev->creation_time != wpt->creation_time)) { + if ((prev == NULL) || (prev->GetCreationTime() != wpt->GetCreationTime())) { route_add_wpt(master, wpt); prev = wpt; } else { @@ -708,7 +707,7 @@ trackfilter_split(void) } if (interval > 0) { - double tr_interval = difftime(buff[j]->creation_time,buff[i]->creation_time); + double tr_interval = difftime(buff[j]->GetCreationTime(),buff[i]->GetCreationTime()); if (tr_interval <= interval) { new_track_flag = 0; } @@ -725,7 +724,7 @@ trackfilter_split(void) printf(MYNAME ": splitting new track\n"); #endif curr = (route_head *) route_head_alloc(); - trackfilter_split_init_rte_name(curr, buff[j]->creation_time); + trackfilter_split_init_rte_name(curr, buff[j]->GetCreationTime()); track_add_head(curr); } if (curr != NULL) { @@ -812,12 +811,12 @@ trackfilter_synth(void) RAD(wpt->longitude))); } if (opt_speed) { - if (oldtime != wpt->creation_time) { + if (oldtime != wpt->GetCreationTime()) { WAYPT_SET(wpt, speed, radtometers(gcdist( RAD(oldlat), RAD(oldlon), RAD(wpt->latitude), RAD(wpt->longitude))) / - labs(wpt->creation_time-oldtime)); + labs(wpt->GetCreationTime()-oldtime)); } else { WAYPT_UNSET(wpt, speed); } @@ -825,7 +824,7 @@ trackfilter_synth(void) } oldlat = wpt->latitude; oldlon = wpt->longitude; - oldtime = wpt->creation_time; + oldtime = wpt->GetCreationTime(); } } } @@ -893,7 +892,7 @@ trackfilter_range(void) /* returns number of track points left after filtering QUEUE_FOR_EACH((queue *)&track->waypoint_list, elem, tmp) { waypoint *wpt = (waypoint *)elem; if (wpt->creation_time > 0) { - inside = ((wpt->creation_time >= start) && (wpt->creation_time <= stop)); + inside = ((wpt->GetCreationTime() >= start) && (wpt->GetCreationTime() <= stop)); } // If the time is mangled so horribly that it's // negative, toss it. diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc index f9da2f0fe..a55d8254d 100644 --- a/gpsbabel/unicsv.cc +++ b/gpsbabel/unicsv.cc @@ -1179,15 +1179,15 @@ unicsv_parse_one_line(char *ibuf) ymd.tm_mon--; if (opt_utc) { - wpt->creation_time = mkgmtime(&ymd); + wpt->SetCreationTime(mkgmtime(&ymd)); } else { - wpt->creation_time = mklocaltime(&ymd); + wpt->SetCreationTime(mklocaltime(&ymd)); } } else if (ymd.tm_hour || ymd.tm_min || ymd.tm_sec) { if (opt_utc) { - wpt->creation_time = mkgmtime(&ymd); + wpt->SetCreationTime(mkgmtime(&ymd)); } else { - wpt->creation_time = mklocaltime(&ymd); + wpt->SetCreationTime(mklocaltime(&ymd)); } } @@ -1729,13 +1729,13 @@ unicsv_waypt_disp_cb(const waypoint *wpt) if (wpt->creation_time >= SECONDS_PER_DAY) { struct tm tm; char buf[32]; - time_t time = wpt->creation_time; + time_t time = wpt->GetCreationTime(); if (opt_utc) { time += atoi(opt_utc) * SECONDS_PER_HOUR; tm = *gmtime(&time); } else { - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = *localtime(&tt); } tm.tm_year += 1900; @@ -1750,13 +1750,13 @@ unicsv_waypt_disp_cb(const waypoint *wpt) if (wpt->creation_time != 0) { struct tm tm; char buf[32], msec[12]; - time_t time = wpt->creation_time; + time_t time = wpt->GetCreationTime(); if (opt_utc) { time += atoi(opt_utc) * SECONDS_PER_HOUR; tm = *gmtime(&time); } else { - const time_t tt = wpt->creation_time; + const time_t tt = wpt->GetCreationTime(); tm = *localtime(&tt); } snprintf(buf, sizeof(buf), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec); diff --git a/gpsbabel/v900.cc b/gpsbabel/v900.cc index 405f084ed..24d8533cf 100644 --- a/gpsbabel/v900.cc +++ b/gpsbabel/v900.cc @@ -326,7 +326,7 @@ v900_read(void) int date, time; date = atoi(line.bas.common.date); time = atoi(line.bas.common.time); - wpt->creation_time = bintime2utc(date, time); + wpt->SetCreationTime(bintime2utc(date, time)); } wpt->speed = KPH_TO_MPS(atoi(line.bas.common.speed)); diff --git a/gpsbabel/vitosmt.cc b/gpsbabel/vitosmt.cc index 5ee3856ca..bee5e1f39 100644 --- a/gpsbabel/vitosmt.cc +++ b/gpsbabel/vitosmt.cc @@ -168,8 +168,8 @@ vitosmt_read(void) tmStruct.tm_sec =(int)floor(seconds); tmStruct.tm_isdst =-1; - wpt_tmp->creation_time = mkgmtime(&tmStruct); - wpt_tmp->microseconds = fmod(1000000*seconds+0.5,1000000); + wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), + fmod(1000000*seconds+0.5,1000000)); wpt_tmp->shortname = (char*) xcalloc(16,1); snprintf(wpt_tmp->shortname, 15 , "WP%04d", ++serial); @@ -254,8 +254,8 @@ vitosmt_waypt_pr(const waypoint *waypointp) WriteDouble(&workbuffer[position], waypointp->altitude); } position += sizeof(double); - QDate date(waypointp->creation_time.date()); - QTime time(waypointp->creation_time.time()); + QDate date(waypointp->GetCreationTime().date()); + QTime time(waypointp->GetCreationTime().time()); workbuffer[position++] = date.year()-100; workbuffer[position++] = date.month(); workbuffer[position++] = date.day(); diff --git a/gpsbabel/vitovtt.cc b/gpsbabel/vitovtt.cc index c4cc2f606..f486a6488 100644 --- a/gpsbabel/vitovtt.cc +++ b/gpsbabel/vitovtt.cc @@ -111,8 +111,7 @@ vitovtt_read(void) tmStruct.tm_sec = scaled_sec / vitovtt_secondscale; microseconds = (scaled_sec % vitovtt_secondscale) / vitovtt_microsecondscale; - wpt_tmp->creation_time = mkgmtime(&tmStruct); - wpt_tmp->microseconds = microseconds; + wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), microseconds); /* * TODO: interpret speed, course, status diff --git a/gpsbabel/vpl.cc b/gpsbabel/vpl.cc index 6eb21c77f..c1be36f80 100644 --- a/gpsbabel/vpl.cc +++ b/gpsbabel/vpl.cc @@ -209,7 +209,7 @@ vpl_parse_75_sentence(const char *ibuf) waypt->hdop = hdop_raw / (double) 8; waypt->vdop = vdop_raw / (double) 8; - waypt->creation_time = mkgmtime(&tm); + waypt->SetCreationTime(mkgmtime(&tm)); track_add_wpt(track_head, waypt); } diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index 4df831532..537a7fbb7 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -659,3 +659,22 @@ waypt_empty_gc_data(const waypoint *wpt) { return (wpt->gc_data == &empty_gc_data); } + +QString +waypoint::CreationTimeXML() const +{ + if (creation_time == 0) { + return NULL; + } + + QDateTime dt = QDateTime::fromTime_t(creation_time); + dt = dt.addMSecs(MICRO_TO_MILLI(microseconds)); + dt = dt.toUTC(); + + const char* format = "yyyy-MM-ddTHH:mm:ssZ"; + if (dt.time().msec()) { + format = "yyyy-MM-ddTHH:mm:ss.zzzZ"; + } + + return dt.toString(format); +} diff --git a/gpsbabel/wbt-200.cc b/gpsbabel/wbt-200.cc index 1f70d51e1..cd393da19 100644 --- a/gpsbabel/wbt-200.cc +++ b/gpsbabel/wbt-200.cc @@ -550,7 +550,7 @@ static waypoint *make_point(double lat, double lon, double alt, time_t tim, cons wpt->latitude = lat;; wpt->longitude = lon; wpt->altitude = alt; - wpt->creation_time = tim; + wpt->SetCreationTime(tim); wpt->shortname = xstrdup(wp_name); return wpt; diff --git a/gpsbabel/wfff_xml.cc b/gpsbabel/wfff_xml.cc index dca8454b1..5336c72fd 100644 --- a/gpsbabel/wfff_xml.cc +++ b/gpsbabel/wfff_xml.cc @@ -255,7 +255,7 @@ void wfff_e(const char *args, const char **unused) } } - wpt_tmp->creation_time = ap_first; + wpt_tmp->SetCreationTime(ap_first); waypt_add(wpt_tmp); diff --git a/gpsbabel/wintec_tes.cc b/gpsbabel/wintec_tes.cc index 5c1561dcd..1f1870b27 100644 --- a/gpsbabel/wintec_tes.cc +++ b/gpsbabel/wintec_tes.cc @@ -71,7 +71,7 @@ wintec_tes_read(void) wpt = waypt_new(); wpt->latitude = latitude / 1.0e7; wpt->longitude = longitude / 1.0e7; - wpt->creation_time = wintec_date_to_time(date); + wpt->SetCreationTime(wintec_date_to_time(date)); // The unit of altitude isn't clear and we have a lot of // samples with wildly negative values, so ignore those for now. wpt->altitude = alt; diff --git a/gpsbabel/xmlgeneric.cc b/gpsbabel/xmlgeneric.cc index a14d52988..80a863de1 100644 --- a/gpsbabel/xmlgeneric.cc +++ b/gpsbabel/xmlgeneric.cc @@ -22,6 +22,7 @@ #include "defs.h" #include "xmlgeneric.h" #include "cet_util.h" +#include #define DEBUG_TAG 0 #if DEBUG_TAG @@ -107,42 +108,30 @@ write_xml_entity_end(gbfile *ofd, const QString& indent, } void -xml_fill_in_time(char *time_string, const time_t timep, int microseconds, int long_or_short) +xml_fill_in_time(char *time_string, const time_t timep, int long_or_short) { - struct tm *tm = gmtime(&timep); - const char *format; - int n; - - if (!tm) { - *time_string = 0; - return; - } + QDateTime dt = QDateTime::fromTime_t(timep); + dt = dt.toUTC(); + const char* format; if (long_or_short == XML_LONG_TIME) { - format = "%02d-%02d-%02dT%02d:%02d:%02d"; + format = "yyyy-MM-ddTHH:mm:ssZ"; + if (dt.time().msec()) { +fprintf(stderr, "this should not be possible"); +abort(); + format = "yyyy-MM-ddTHH:mm:ss.zzzZ"; + } } else { - format = "%02d%02d%02dT%02d%02d%02d"; - } - n = sprintf(time_string, format, - tm->tm_year+1900, - tm->tm_mon+1, - tm->tm_mday, - tm->tm_hour, - tm->tm_min, - tm->tm_sec); - if (microseconds) { - n += sprintf(time_string + n, ".%03d", microseconds / 1000); + format = "yyyyMMddTHHmmssZ"; } - time_string[n++] = 'Z'; - time_string[n++] = '\0'; - + strcpy(time_string, qPrintable(dt.toString(format))); } void xml_write_time(gbfile *ofd, const time_t timep, int microseconds, const char *elname) { char time_string[64]; - xml_fill_in_time(time_string, timep, microseconds, XML_LONG_TIME); + xml_fill_in_time(time_string, timep, XML_LONG_TIME); if (time_string[0]) { gbfprintf(ofd, "<%s>%s\n", elname, diff --git a/gpsbabel/xmlgeneric.h b/gpsbabel/xmlgeneric.h index 77ad6c0d3..f299ba513 100644 --- a/gpsbabel/xmlgeneric.h +++ b/gpsbabel/xmlgeneric.h @@ -52,8 +52,7 @@ void write_xml_entity_end(gbfile* ofd, const QString& indent, const QString& tag void write_optional_xml_entity(gbfile* ofd, const QString& indent, const QString& tag, const QString& value); void xml_write_time(gbfile* ofd, const time_t timep, int microseconds, const char* elname); -void xml_fill_in_time(char* time_string, const time_t timep, int microseconds, - int long_or_short); +void xml_fill_in_time(char* time_string, const time_t timep, int long_or_short); void write_xml_header(gbfile* ofd); void xml_ignore_tags(const char** taglist); diff --git a/gpsbabel/xol.cc b/gpsbabel/xol.cc index 0f258f39a..59efe39fc 100644 --- a/gpsbabel/xol.cc +++ b/gpsbabel/xol.cc @@ -199,11 +199,9 @@ xol_fatal_outside(const waypoint *wpt) static void xol_write_time(const waypoint *wpt) { - char time_string[64]; - - xml_fill_in_time(time_string, wpt->creation_time, wpt->microseconds, XML_LONG_TIME); - if (time_string[0]) { - gbfprintf(fout, " timestamp=\"%s\"", time_string); + QString time_string = wpt->CreationTimeXML(); + if (!time_string.isEmpty()) { + gbfprintf(fout, " timestamp=\"%s\"", qPrintable(time_string)); } }