From 31675e8d99ca20c77f322f69bccc8eb64e4ca63e Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Tue, 23 Oct 2001 17:40:55 +0000 Subject: convert an icaltimetype to a tm (tm_to_icaltimetype): vice versa 2001-10-23 JP Rosevear * cal-util/timeutil.c (icaltimetype_to_tm): convert an icaltimetype to a tm (tm_to_icaltimetype): vice versa * cal-util/timeutil.h: new protos * conduits/calendar/calendar-conduit.c: replace all mktime and localtime calls (except for debugging calls) * conduits/todo/todo-conduit.c: ditto (comp_from_remote_record): make sure the completed time is in UTC svn path=/trunk/; revision=13946 --- calendar/cal-util/timeutil.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'calendar/cal-util/timeutil.c') diff --git a/calendar/cal-util/timeutil.c b/calendar/cal-util/timeutil.c index f960346477..986971ef37 100644 --- a/calendar/cal-util/timeutil.c +++ b/calendar/cal-util/timeutil.c @@ -520,3 +520,47 @@ time_from_isodate (const char *str) return icaltime_as_timet_with_zone (tt, utc_zone); } +struct tm +icaltimetype_to_tm (struct icaltimetype *itt) +{ + struct tm tm; + + memset (&tm, 0, sizeof (struct tm)); + + if (!itt->is_date) { + tm.tm_sec = itt->second; + tm.tm_min = itt->minute; + tm.tm_hour = itt->hour; + } + + tm.tm_mday = itt->day; + tm.tm_mon = itt->month - 1; + tm.tm_year = itt->year - 1900; + tm.tm_isdst = -1; + + return tm; +} + +struct icaltimetype +tm_to_icaltimetype (struct tm *tm, gboolean is_date) +{ + struct icaltimetype itt; + + memset (&itt, 0, sizeof (struct icaltimetype)); + + if (!is_date) { + itt.second = tm->tm_sec; + itt.minute = tm->tm_min; + itt.hour = tm->tm_hour; + } + + itt.day = tm->tm_mday; + itt.month = tm->tm_mon + 1; + itt.year = tm->tm_year+ 1900; + + itt.is_utc = 0; + itt.is_date = is_date; + + return itt; +} + -- cgit v1.2.3