From 7e35463832751ecfa20a10949eac4188a8c00125 Mon Sep 17 00:00:00 2001 From: Damon Chaplin Date: Wed, 3 Oct 2001 04:34:53 +0000 Subject: save the EXDATE as a DATE-TIME value, since we know the exact time. Fixes 2001-10-03 Damon Chaplin * gui/comp-util.c (cal_comp_util_add_exdate): save the EXDATE as a DATE-TIME value, since we know the exact time. Fixes bug #11278. (Before we were setting is_date, but icaltime_from_timet_with_zone() didn't convert it properly. We need to figure out how to handle DATEs when using time_t's.) * gui/dialogs/recurrence-page.c (get_exception_string): use e_time_format_date_and_time() so we show the time as well, if the exception is a DATE-TIME value. * cal-util/timeutil.c: removed time_add_month(), time_year_begin(), time_month_begin() & time_week_begin() - old pre-timezone functions which we no longer use. * cal-util/cal-recur.c (cal_recur_from_icalproperty): set ir.until.is_date to FALSE before converting to a time_t. Hopefully fixes bug #5034. svn path=/trunk/; revision=13366 --- calendar/ChangeLog | 20 +++++++ calendar/cal-util/cal-recur.c | 5 ++ calendar/cal-util/timeutil.c | 103 +++++++-------------------------- calendar/cal-util/timeutil.h | 9 --- calendar/gui/comp-util.c | 2 +- calendar/gui/dialogs/recurrence-page.c | 3 +- 6 files changed, 49 insertions(+), 93 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 76ca1ddc75..8a69641bfe 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,23 @@ +2001-10-03 Damon Chaplin + + * gui/comp-util.c (cal_comp_util_add_exdate): save the EXDATE as a + DATE-TIME value, since we know the exact time. Fixes bug #11278. + (Before we were setting is_date, but icaltime_from_timet_with_zone() + didn't convert it properly. We need to figure out how to handle DATEs + when using time_t's.) + + * gui/dialogs/recurrence-page.c (get_exception_string): use + e_time_format_date_and_time() so we show the time as well, if the + exception is a DATE-TIME value. + + * cal-util/timeutil.c: removed time_add_month(), time_year_begin(), + time_month_begin() & time_week_begin() - old pre-timezone functions + which we no longer use. + + * cal-util/cal-recur.c (cal_recur_from_icalproperty): set + ir.until.is_date to FALSE before converting to a time_t. + Hopefully fixes bug #5034. + 2001-10-02 Ettore Perazzoli * gui/dialogs/comp-editor.c (setup_widgets): Use diff --git a/calendar/cal-util/cal-recur.c b/calendar/cal-util/cal-recur.c index 9afcee9784..83a0bccae9 100644 --- a/calendar/cal-util/cal-recur.c +++ b/calendar/cal-util/cal-recur.c @@ -878,9 +878,14 @@ cal_recur_from_icalproperty (icalproperty *prop, gboolean exception, ir.until.hour = 23; ir.until.minute = 59; ir.until.second = 59; + ir.until.is_date = FALSE; r->enddate = icaltime_as_timet_with_zone (ir.until, zone); +#if 0 + g_print (" until: %li - %s", r->enddate, ctime (&r->enddate)); +#endif + } else { /* If UNTIL is a DATE-TIME, it must be in UTC. */ icaltimezone *utc_zone; diff --git a/calendar/cal-util/timeutil.c b/calendar/cal-util/timeutil.c index f66d851399..aff465b8df 100644 --- a/calendar/cal-util/timeutil.c +++ b/calendar/cal-util/timeutil.c @@ -81,87 +81,6 @@ time_add_week (time_t time, int weeks) return time_add_day (time, weeks * 7); } -time_t -time_add_month (time_t time, int months) -{ - struct tm *tm = localtime (&time); - time_t new_time; - int mday; - - mday = tm->tm_mday; - - tm->tm_mon += months; - tm->tm_isdst = -1; - if ((new_time = mktime (tm)) == -1) { - g_message ("time_add_month(): mktime() could not handling adding %d months with\n", - months); - print_time_t (time); - printf ("\n"); - return time; - } - tm = localtime (&new_time); - if (tm->tm_mday < mday) { - tm->tm_mon--; - tm->tm_mday = time_days_in_month (tm->tm_year+1900, tm->tm_mon); - return new_time = mktime (tm); - } - else - return new_time; -} - -time_t -time_year_begin (time_t t) -{ - struct tm tm; - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mon = 0; - tm.tm_mday = 1; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -time_t -time_month_begin (time_t t) -{ - struct tm tm; - - tm = *localtime (&t); - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mday = 1; - tm.tm_isdst = -1; - - return mktime (&tm); -} - -/* Returns the start of the week. week_start_day should use the same values - as mktime(), i.e. 0 (Sun) to 6 (Sat). */ -time_t -time_week_begin (time_t t, int week_start_day) -{ - struct tm tm; - int offset; - - tm = *localtime (&t); - - /* Calculate the current offset from the week start day. */ - offset = (tm.tm_wday + 7 - week_start_day) % 7; - - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mday -= offset; - tm.tm_isdst = -1; - - return mktime (&tm); -} - /* Returns the start of the day, according to the local time. */ time_t time_day_begin (time_t t) @@ -238,6 +157,11 @@ time_add_week_with_zone (time_t time, int weeks, icaltimezone *zone) /* Adds or subtracts a number of months to/from the given time_t value, using the given timezone. + + If the day would be off the end of the month (e.g. adding 1 month to + 30th January, would lead to an invalid day, 30th February), it moves it + down to the last day in the month, e.g. 28th Feb (or 29th in a leap year.) + NOTE: this function is only here to make the transition to the timezone functions easier. New code should use icaltimetype values and icaltime_adjust() to add or subtract days, hours, minutes & seconds. */ @@ -245,6 +169,7 @@ time_t time_add_month_with_zone (time_t time, int months, icaltimezone *zone) { struct icaltimetype tt; + int day, days_in_month; /* Convert to an icaltimetype. */ tt = icaltime_from_timet_with_zone (time, FALSE, zone); @@ -252,9 +177,21 @@ time_add_month_with_zone (time_t time, int months, icaltimezone *zone) /* Add on the number of months. */ tt.month += months; - /* Normalize it, fixing any overflow. */ + /* Save the day, and set it to 1, so we don't overflow into the next + month. */ + day = tt.day; + tt.day = 1; + + /* Normalize it, fixing any month overflow. */ tt = icaltime_normalize (tt); + /* If we go past the end of a month, set it to the last day. */ + days_in_month = time_days_in_month (tt.year, tt.month - 1); + if (day > days_in_month) + day = days_in_month; + + tt.day = day; + /* Convert back to a time_t. */ return icaltime_as_timet_with_zone (tt, zone); } @@ -430,6 +367,8 @@ time_days_in_month (int year, int month) { int days; + g_print ("Year: %i Month: %i\n", year, month); + g_return_val_if_fail (year >= 1900, 0); g_return_val_if_fail ((month >= 0) && (month < 12), 0); diff --git a/calendar/cal-util/timeutil.h b/calendar/cal-util/timeutil.h index 0e2795b287..1ae0b45f72 100644 --- a/calendar/cal-util/timeutil.h +++ b/calendar/cal-util/timeutil.h @@ -59,15 +59,6 @@ time_t time_from_isodate (const char *str); /* Add or subtract a number of days, weeks or months. */ time_t time_add_day (time_t time, int days); time_t time_add_week (time_t time, int weeks); -time_t time_add_month (time_t time, int months); - -/* Returns the beginning of the year or month. */ -time_t time_year_begin (time_t t); -time_t time_month_begin (time_t t); - -/* Returns the beginning of the week. week_start_day should use the same values - as mktime(), i.e. 0 (Sun) to 6 (Sat). */ -time_t time_week_begin (time_t t, int week_start_day); /* Returns the beginning or end of the day. */ time_t time_day_begin (time_t t); diff --git a/calendar/gui/comp-util.c b/calendar/gui/comp-util.c index f0376e2a99..995e69a270 100644 --- a/calendar/gui/comp-util.c +++ b/calendar/gui/comp-util.c @@ -49,7 +49,7 @@ cal_comp_util_add_exdate (CalComponent *comp, time_t t, icaltimezone *zone) cdt = g_new (CalComponentDateTime, 1); cdt->value = g_new (struct icaltimetype, 1); - *cdt->value = icaltime_from_timet_with_zone (t, TRUE, zone); + *cdt->value = icaltime_from_timet_with_zone (t, FALSE, zone); cdt->tzid = g_strdup (icaltimezone_get_tzid (zone)); list = g_slist_append (list, cdt); diff --git a/calendar/gui/dialogs/recurrence-page.c b/calendar/gui/dialogs/recurrence-page.c index 10946805ed..ddd37fa3b2 100644 --- a/calendar/gui/dialogs/recurrence-page.c +++ b/calendar/gui/dialogs/recurrence-page.c @@ -419,7 +419,8 @@ get_exception_string (CalComponentDateTime *dt) dt->value->month - 1, dt->value->year); - strftime (buf, sizeof (buf), _("%a %b %d %Y"), &tmp_tm); + e_time_format_date_and_time (&tmp_tm, calendar_config_get_24_hour_format(), FALSE, FALSE, buf, sizeof (buf)); + return buf; } -- cgit v1.2.3