From e881a9d574062ecf6d1ddaef6077ec04115a9226 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Tue, 11 Nov 2008 12:35:59 -0400 Subject: [PATCH] Adding a function to compare timestamps. I will use it to workaround the fact that query-by-updated on google protocol is inclusive. The idea is to only report an entry if its timestamp is bigger than the one that was stored on anchor. --- src/gcalendar.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/gcalendar.c b/src/gcalendar.c index b483253..0262250 100644 --- a/src/gcalendar.c +++ b/src/gcalendar.c @@ -26,6 +26,10 @@ * */ +#define _XOPEN_SOURCE /* man page say: glibc2 needs this */ +#include +#include + #include #include #include @@ -49,6 +53,36 @@ #include #include "xslt_aux.h" + +static int timestamp_cmp(char *timestamp1, char *timestamp2) +{ + /* timestamp (RFC3339) formating string */ + char format[] = "%FT%T"; + struct tm first, second; + time_t t_first, t_second; + int result = 0; + + /* From timestamp string to time structure */ + strptime(timestamp1, format, &first); + strptime(timestamp2, format, &second); + + /* From time structure to calendar time (since + * Epoch (00:00:00 UTC, January 1, 1970) + */ + t_first = mktime(&first); + t_second = mktime(&second); + + if (t_first == t_second) + result = 0; + else if (t_first > t_second) + result = 1; + else if (t_first < t_second) + result = -1; + + return result; + +} + struct gc_plgdata { char *url; -- 2.11.4.GIT