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

fix dotnet time conversion #784

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ time_t mklocaltime(struct tm* t);
time_t mkgmtime(struct tm* t);
bool gpsbabel_testmode();
gpsbabel::DateTime current_time();
void dotnet_time_to_time_t(double dotnet, time_t* t, int* millisecs);
QDateTime dotnet_time_to_qdatetime(long long dotnet);
const char* get_cache_icon(const Waypoint* waypointp);
const char* gs_get_cachetype(geocache_type t);
const char* gs_get_container(geocache_container t);
Expand Down
6 changes: 6 additions & 0 deletions reference/dotnet.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0,40,105 # .net epoch midnight Jan 1, 1
4999,40.5,105.5 # should round down
5001,40.5,105.5 # should round up
864000000000,41,106 # (60sec/min * 60min/hr * 24hr/day) / 100e-9 sec = midnight Jan 2, 1.
637739532350000000,42,107 # GMT / UTC Date Time 2021-12-01 11:00:35 + 0.0000000 second

6 changes: 6 additions & 0 deletions reference/dotnet~csv.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
No,Latitude,Longitude,Name,Date,Time
1,40.000000,105.000000,"WPT001",0001/01/01,00:00:00
2,40.500000,105.500000,"WPT002",0001/01/01,00:00:00
3,40.500000,105.500000,"WPT003",0001/01/01,00:00:00.001
4,41.000000,106.000000,"WPT004",0001/01/02,00:00:00
5,42.000000,107.000000,"WPT005",2021/12/01,11:00:35
13 changes: 13 additions & 0 deletions testo.d/unitconversion.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ echo 'OFIELD PATH_DISTANCE_NAUTICAL_MILES,"","%.6e"' >> ${TMPDIR}/distance3.styl

gpsbabel -t -i xcsv,style=${TMPDIR}/distance3.style -f ${REFERENCE}/distance3.csv -o xcsv,style=${TMPDIR}/distance3.style -F ${TMPDIR}/distance3~csv.csv
compare ${REFERENCE}/distance3~csv.csv ${TMPDIR}/distance3~csv.csv

echo 'DESCRIPTION dotnet test' > ${TMPDIR}/dotnet.style
echo 'EXTENSION csv' >> ${TMPDIR}/dotnet.style
echo 'DATATYPE WAYPOINT' >> ${TMPDIR}/dotnet.style
echo 'FIELD_DELIMITER COMMA' >> ${TMPDIR}/dotnet.style
echo 'RECORD_DELIMITER NEWLINE' >> ${TMPDIR}/dotnet.style
echo 'BADCHARS COMMA' >> ${TMPDIR}/dotnet.style
echo 'IFIELD NET_TIME, "","%lld"' >> ${TMPDIR}/dotnet.style
echo 'IFIELD LAT_DECIMAL,"","%.9f"' >> ${TMPDIR}/dotnet.style
echo 'IFIELD LON_DECIMAL,"","%.9f"' >> ${TMPDIR}/dotnet.style
gpsbabel -i xcsv,style=${TMPDIR}/dotnet.style -f ${REFERENCE}/dotnet.csv -o unicsv,utc=0 -F ${TMPDIR}/dotnet.csv
compare ${REFERENCE}/dotnet~csv.csv ${TMPDIR}/dotnet.csv

18 changes: 4 additions & 14 deletions util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -765,23 +765,13 @@ current_time()
* internals and since we're in the GPS biz, timestamps before 1/1/1970 aren't
* that interesting to us anyway.
*/
#define EPOCH_TICKS 621355968000000000.0
void dotnet_time_to_time_t(double dotnet, time_t* t, int* millisecs)
QDateTime dotnet_time_to_qdatetime(long long dotnet)
{
// TODO: replace this with better interface with normal return values
// and called via a QDateTime.
*t = (dotnet - EPOCH_TICKS) / 10000000.;
#if LATER
// TODO: work out fractional seconds.
if (millisecs) {
*millisecs = dotnet % 10000;
}
#else
(void)millisecs;
#endif
QDateTime epoch = QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), Qt::UTC);
qint64 millisecs = (dotnet + 5000)/ 10000;
return epoch.addMSecs(millisecs);
}


/*
* Return a pointer to a constant string that is suitable for icon lookup
* based on geocache attributes. The strings used are those present in
Expand Down
8 changes: 5 additions & 3 deletions xcsv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,11 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle:
wpt->SetCreationTime(xml_parse_time(s));
break;
case XcsvStyle::XT_NET_TIME: {
fatal("XT_NET_TIME can't have possibly ever worked.");
// time_t tt = wpt->GetCreationTime();
// dotnet_time_to_time_t(atof(s), &tt, &wpt->microseconds);
bool ok;
wpt->SetCreationTime(dotnet_time_to_qdatetime(value.toLongLong(&ok)));
if (!ok) {
warning("parse of string '%s' on line number %d as NET_TIME failed.\n", s, line_no);
}
}
break;
case XcsvStyle::XT_GEOCACHE_LAST_FOUND:
Expand Down
2 changes: 1 addition & 1 deletion xmldoc/chapters/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ longitude)
</para>
<para>example:
</para>
<screen format="linespecific">IFIELD NET_TIME,&quot;&quot;,&quot;%f&quot;
<screen format="linespecific">IFIELD NET_TIME,&quot;&quot;,&quot;%lld&quot;
</screen>
</section>
<section id="style_def_geodiff">
Expand Down