X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=parse.c;h=25d4a99370a55889ceae18c7ed3af6efa86cf73c;hb=3bd1abdfc781f36d2f87b39134dd4620645fe8ac;hp=52609a636c67e0205f8afe13a0924b1dfcca3381;hpb=f46e9f571e92156cd764d6711cac671c053260a1;p=ext%2Fsubsurface.git diff --git a/parse.c b/parse.c index 52609a6..25d4a99 100644 --- a/parse.c +++ b/parse.c @@ -90,7 +90,9 @@ static int to_feet(depth_t depth) static int to_C(temperature_t temp) { - return (temp.mkelvin + 272150) / 1000; + if (!temp.mkelvin) + return 0; + return (temp.mkelvin - 273150) / 1000; } static int to_PSI(pressure_t pressure) @@ -183,6 +185,7 @@ static time_t utc_mktime(struct tm *tm) int month = tm->tm_mon; int day = tm->tm_mday; + /* First normalize relative to 1900 */ if (year < 70) year += 100; else if (year > 1900) @@ -233,6 +236,26 @@ static void divetime(char *buffer, void *_when) free(buffer); } +/* Libdivecomputer: "2011-03-20 10:22:38" */ +static void divedatetime(char *buffer, void *_when) +{ + int y,m,d; + int hr,min,sec; + time_t *when = _when; + + if (sscanf(buffer, "%d-%d-%d %d:%d:%d", + &y, &m, &d, &hr, &min, &sec) == 6) { + tm.tm_year = y; + tm.tm_mon = m-1; + tm.tm_mday = d; + tm.tm_hour = hr; + tm.tm_min = min; + tm.tm_sec = sec; + *when = utc_mktime(&tm); + } + free(buffer); +} + union int_or_float { long i; double fp; @@ -403,6 +426,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf) return; if (match("time", last, divetime, buf, &dive->when)) return; + if (match("datetime", last, divedatetime, buf, &dive->when)) + return; nonmatch("dive", name, last, buf); }