mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Add 'datetime' parsing for libdivecomputer xml files
I think this gets me dates on all my dives. So now I could start sorting them and removing duplicates. But before I try to remove dups, I guess I should compare the libdivecomputer ones against the suunto ones. Because I bet they have various "interesting" issues like using Bar vs Atm etc. "But XML is portable". Crazy people. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
716a680920
commit
3bd1abdfc7
1 changed files with 23 additions and 0 deletions
23
parse.c
23
parse.c
|
@ -185,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)
|
||||
|
@ -235,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;
|
||||
|
@ -405,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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue