diff options
author | JP Rosevear <jpr@ximian.com> | 2001-10-24 01:40:55 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2001-10-24 01:40:55 +0800 |
commit | 31675e8d99ca20c77f322f69bccc8eb64e4ca63e (patch) | |
tree | 38f83373eb1fae8436c68f669d0a1e28d0e7a656 /calendar | |
parent | 2ea98fb813283a72698682e3f51f3ae13b614889 (diff) | |
download | gsoc2013-evolution-31675e8d99ca20c77f322f69bccc8eb64e4ca63e.tar.gz gsoc2013-evolution-31675e8d99ca20c77f322f69bccc8eb64e4ca63e.tar.zst gsoc2013-evolution-31675e8d99ca20c77f322f69bccc8eb64e4ca63e.zip |
convert an icaltimetype to a tm (tm_to_icaltimetype): vice versa
2001-10-23 JP Rosevear <jpr@ximian.com>
* 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
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/ChangeLog | 14 | ||||
-rw-r--r-- | calendar/cal-util/timeutil.c | 44 | ||||
-rw-r--r-- | calendar/cal-util/timeutil.h | 7 | ||||
-rw-r--r-- | calendar/conduits/calendar/calendar-conduit.c | 58 | ||||
-rw-r--r-- | calendar/conduits/todo/todo-conduit.c | 22 |
5 files changed, 103 insertions, 42 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 37dbd6ba80..f50d31ddb2 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,17 @@ +2001-10-23 JP Rosevear <jpr@ximian.com> + + * 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 + 2001-10-23 Rodrigo Moya <rodrigo@ximian.com> * cal-client/cal-query.c (cal_query_construct) set priv->corba_query 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; +} + diff --git a/calendar/cal-util/timeutil.h b/calendar/cal-util/timeutil.h index 1ae0b45f72..2ca61b45a2 100644 --- a/calendar/cal-util/timeutil.h +++ b/calendar/cal-util/timeutil.h @@ -109,4 +109,11 @@ time_t time_day_end_with_zone (time_t time, icaltimezone *zone); void time_to_gdate_with_zone (GDate *date, time_t time, icaltimezone *zone); +/************************************************************************** + * struct tm manipulation + **************************************************************************/ + +struct tm icaltimetype_to_tm (struct icaltimetype *itt); +struct icaltimetype tm_to_icaltimetype (struct tm *tm, gboolean is_date); + #endif diff --git a/calendar/conduits/calendar/calendar-conduit.c b/calendar/conduits/calendar/calendar-conduit.c index b9f19489e7..a985ca0e35 100644 --- a/calendar/conduits/calendar/calendar-conduit.c +++ b/calendar/conduits/calendar/calendar-conduit.c @@ -507,9 +507,9 @@ local_record_from_comp (ECalLocalRecord *local, CalComponent *comp, ECalConduitC CalComponentText summary; GSList *d_list = NULL, *edl = NULL, *l; CalComponentText *description; - CalComponentDateTime dt_start, dt_end, dt; + CalComponentDateTime dt_start, dt_end; CalComponentClassification classif; - time_t dt_time; + icaltimezone *default_tz = get_default_timezone (); int i; g_return_if_fail (local != NULL); @@ -561,18 +561,20 @@ local_record_from_comp (ECalLocalRecord *local, CalComponent *comp, ECalConduitC cal_component_get_dtstart (comp, &dt_start); cal_component_get_dtend (comp, &dt_end); if (dt_start.value) { - dt_time = icaltime_as_timet_with_zone (*dt_start.value, - get_timezone (ctxt->client, dt_start.tzid)); - local->appt->begin = *localtime (&dt_time); + icaltimezone_convert_time (dt_start.value, + get_timezone (ctxt->client, dt_start.tzid), + default_tz); + local->appt->begin = icaltimetype_to_tm (dt_start.value); } if (dt_start.value && dt_end.value) { if (is_all_day (ctxt->client, &dt_start, &dt_end)) { local->appt->event = 1; } else { - dt_time = icaltime_as_timet_with_zone (*dt_end.value, - get_timezone (ctxt->client, dt_end.tzid)); - local->appt->end = *localtime (&dt_time); + icaltimezone_convert_time (dt_end.value, + get_timezone (ctxt->client, dt_end.tzid), + default_tz); + local->appt->end = icaltimetype_to_tm (dt_end.value); local->appt->event = 0; } } else { @@ -647,8 +649,10 @@ local_record_from_comp (ECalLocalRecord *local, CalComponent *comp, ECalConduitC local->appt->repeatForever = 1; } else { local->appt->repeatForever = 0; - dt_time = icaltime_as_timet_with_zone (recur->until, get_timezone (ctxt->client, dt.tzid)); - local->appt->repeatEnd = *localtime (&dt_time); + icaltimezone_convert_time (&recur->until, + icaltimezone_get_utc_timezone (), + default_tz); + local->appt->repeatEnd = icaltimetype_to_tm (&recur->until); } cal_component_free_recur_list (list); @@ -661,14 +665,10 @@ local_record_from_comp (ECalLocalRecord *local, CalComponent *comp, ECalConduitC for (l = edl, i = 0; l != NULL; l = l->next, i++) { CalComponentDateTime *dt = l->data; - if (dt->value->is_date) { - local->appt->exception[i].tm_mday = dt->value->day; - local->appt->exception[i].tm_mon = dt->value->month - 1; - local->appt->exception[i].tm_year = dt->value->year - 1900; - } else { - dt_time = icaltime_as_timet_with_zone (*dt->value, get_timezone (ctxt->client, dt->tzid)); - local->appt->exception[i] = *localtime (&dt_time); - } + icaltimezone_convert_time (dt->value, + icaltimezone_get_utc_timezone (), + default_tz); + *local->appt->exception = icaltimetype_to_tm (dt->value); } cal_component_free_exdate_list (edl); @@ -758,20 +758,18 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, } if (!is_empty_time (appt.begin)) { - it = icaltime_from_timet_with_zone (mktime (&appt.begin), FALSE, timezone); + it = tm_to_icaltimetype (&appt.begin, FALSE); dt.value = ⁢ cal_component_set_dtstart (comp, &dt); } if (appt.event) { - time_t t = mktime (&appt.begin); - - t = time_day_end_with_zone (t, timezone); - it = icaltime_from_timet_with_zone (t, FALSE, timezone); + it = tm_to_icaltimetype (&appt.begin, FALSE); + icaltime_adjust (&it, 1, 0, 0, 0); dt.value = ⁢ cal_component_set_dtend (comp, &dt); } else if (!is_empty_time (appt.end)) { - it = icaltime_from_timet_with_zone (mktime (&appt.end), FALSE, timezone); + it = tm_to_icaltimetype (&appt.end, FALSE); dt.value = ⁢ cal_component_set_dtend (comp, &dt); } @@ -833,8 +831,7 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, recur.week_start = get_ical_day (appt.repeatWeekstart); if (!appt.repeatForever) { - time_t t = mktime (&appt.repeatEnd); - recur.until = icaltime_from_timet_with_zone (t, FALSE, timezone); + recur.until = tm_to_icaltimetype (&appt.repeatEnd, TRUE); } list = g_slist_append (list, &recur); @@ -853,16 +850,9 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, dt->tzid = NULL; ex = appt.exception[i]; - *dt->value = icaltime_from_timet_with_zone (mktime (&ex), TRUE, timezone); + *dt->value = tm_to_icaltimetype (&ex, TRUE); edl = g_slist_prepend (edl, dt); - - INFO ("%d %d %d %d %d %d %d %d %d", - ex.tm_sec, ex.tm_min, - ex.tm_hour, ex.tm_mday, - ex.tm_mon, ex.tm_year, - ex.tm_wday, ex.tm_yday, - ex.tm_isdst); } cal_component_set_exdate_list (comp, edl); cal_component_free_exdate_list (edl); diff --git a/calendar/conduits/todo/todo-conduit.c b/calendar/conduits/todo/todo-conduit.c index ca59b04bd6..ed039b10b7 100644 --- a/calendar/conduits/todo/todo-conduit.c +++ b/calendar/conduits/todo/todo-conduit.c @@ -364,9 +364,9 @@ local_record_from_comp (EToDoLocalRecord *local, CalComponent *comp, EToDoCondui GSList *d_list = NULL; CalComponentText *description; CalComponentDateTime due; - time_t due_time; CalComponentClassification classif; - + icaltimezone *default_tz = get_default_timezone (); + LOG ("local_record_from_comp\n"); g_return_if_fail (local != NULL); @@ -417,9 +417,10 @@ local_record_from_comp (EToDoLocalRecord *local, CalComponent *comp, EToDoCondui cal_component_get_due (comp, &due); if (due.value) { - due_time = icaltime_as_timet_with_zone (*due.value, get_timezone (ctxt->client, due.tzid)); - - local->todo->due = *localtime (&due_time); + icaltimezone_convert_time (due.value, + get_timezone (ctxt->client, due.tzid), + default_tz); + local->todo->due = icaltimetype_to_tm (due.value); local->todo->indefinite = 0; } else { local->todo->indefinite = 1; @@ -493,10 +494,10 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, { CalComponent *comp; struct ToDo todo; - struct icaltimetype now = icaltime_from_timet_with_zone (time (NULL), FALSE, timezone); CalComponentText summary = {NULL, NULL}; CalComponentDateTime dt = {NULL, icaltimezone_get_tzid (timezone)}; - struct icaltimetype due; + struct icaltimetype due, now; + icaltimezone *utc_zone; int priority; char *txt; @@ -505,6 +506,10 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, memset (&todo, 0, sizeof (struct ToDo)); unpack_ToDo (&todo, remote->record, remote->length); + utc_zone = icaltimezone_get_utc_timezone (); + now = icaltime_from_timet_with_zone (time (NULL), FALSE, + utc_zone); + if (in_comp == NULL) { comp = cal_component_new (); cal_component_set_new_vtype (comp, CAL_COMPONENT_TODO); @@ -537,12 +542,13 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, if (todo.complete) { int percent = 100; + cal_component_set_completed (comp, &now); cal_component_set_percent (comp, &percent); } if (!is_empty_time (todo.due)) { - due = icaltime_from_timet_with_zone (mktime (&todo.due), FALSE, timezone); + due = tm_to_icaltimetype (&todo.due, FALSE); dt.value = &due; cal_component_set_due (comp, &dt); } |