diff options
author | Damon Chaplin <damon@ximian.com> | 2001-07-11 11:46:33 +0800 |
---|---|---|
committer | Damon Chaplin <damon@src.gnome.org> | 2001-07-11 11:46:33 +0800 |
commit | 552d3501e9bf05d42ce6f342e85a526a1cea702c (patch) | |
tree | 450dc99dc05de51b48ddc4e778a6875428b2381b /libical | |
parent | cac847c063f91e669e5110c1455a0fc6ccf859d8 (diff) | |
download | gsoc2013-evolution-552d3501e9bf05d42ce6f342e85a526a1cea702c.tar gsoc2013-evolution-552d3501e9bf05d42ce6f342e85a526a1cea702c.tar.gz gsoc2013-evolution-552d3501e9bf05d42ce6f342e85a526a1cea702c.tar.bz2 gsoc2013-evolution-552d3501e9bf05d42ce6f342e85a526a1cea702c.tar.lz gsoc2013-evolution-552d3501e9bf05d42ce6f342e85a526a1cea702c.tar.xz gsoc2013-evolution-552d3501e9bf05d42ce6f342e85a526a1cea702c.tar.zst gsoc2013-evolution-552d3501e9bf05d42ce6f342e85a526a1cea702c.zip |
don't convert DATE values.
2001-07-10 Damon Chaplin <damon@ximian.com>
* src/libical/icaltimezone.c (icaltimezone_convert_time): don't convert
DATE values.
* src/libical/icaltime.c (icaltime_from_timet_with_zone):
(icaltime_as_timet_with_zone): changed so they do not convert DATE
values according to the timezone.
* src/libical/icaltime.[hc]: added icaltime_current_time_with_zone()
and icaltime_today() functions.
svn path=/trunk/; revision=10983
Diffstat (limited to 'libical')
-rw-r--r-- | libical/ChangeLog | 12 | ||||
-rw-r--r-- | libical/src/libical/icaltime.c | 126 | ||||
-rw-r--r-- | libical/src/libical/icaltime.h | 6 | ||||
-rw-r--r-- | libical/src/libical/icaltimezone.c | 5 |
4 files changed, 107 insertions, 42 deletions
diff --git a/libical/ChangeLog b/libical/ChangeLog index e24a36208f..111a699c4d 100644 --- a/libical/ChangeLog +++ b/libical/ChangeLog @@ -1,3 +1,15 @@ +2001-07-10 Damon Chaplin <damon@ximian.com> + + * src/libical/icaltimezone.c (icaltimezone_convert_time): don't convert + DATE values. + + * src/libical/icaltime.c (icaltime_from_timet_with_zone): + (icaltime_as_timet_with_zone): changed so they do not convert DATE + values according to the timezone. + + * src/libical/icaltime.[hc]: added icaltime_current_time_with_zone() + and icaltime_today() functions. + 2001-07-09 Damon Chaplin <damon@ximian.com> * src/libical/icaltime.c (icaltime_adjust): forgot to compile before diff --git a/libical/src/libical/icaltime.c b/libical/src/libical/icaltime.c index 6c720b7941..8ae2752152 100644 --- a/libical/src/libical/icaltime.c +++ b/libical/src/libical/icaltime.c @@ -77,7 +77,7 @@ icaltime_from_timet(time_t tm, int is_date) struct icaltimetype icaltime_from_timet_with_zone(time_t tm, int is_date, icaltimezone *zone) { - struct icaltimetype tt = icaltime_null_time(); + struct icaltimetype tt; struct tm t; icaltimezone *utc_zone; @@ -90,25 +90,42 @@ icaltime_from_timet_with_zone(time_t tm, int is_date, icaltimezone *zone) tt.year = t.tm_year + 1900; tt.month = t.tm_mon + 1; tt.day = t.tm_mday; - tt.hour = t.tm_hour; - tt.minute = t.tm_min; - tt.second = t.tm_sec; tt.is_utc = (zone == utc_zone) ? 1 : 0; tt.is_date = is_date; tt.is_daylight = 0; - - /* Use our timezone functions to convert to the required timezone. */ - icaltimezone_convert_time (&tt, utc_zone, zone); + tt.zone = NULL; if (is_date) { - /* FIXME: is_daylight may need to be changed. */ - tt.second = tt.minute = tt.hour = 0; + /* We don't convert DATE values between timezones. */ + tt.hour = 0; + tt.minute = 0; + tt.second = 0; + } else { + tt.hour = t.tm_hour; + tt.minute = t.tm_min; + tt.second = t.tm_sec; + + /* Use our timezone functions to convert to the required timezone. */ + icaltimezone_convert_time (&tt, utc_zone, zone); } return tt; } +/* Returns the current time in the given timezone, as an icaltimetype. */ +struct icaltimetype icaltime_current_time_with_zone(icaltimezone *zone) +{ + return icaltime_from_timet_with_zone (time (NULL), 0, zone); +} + +/* Returns the current day as an icaltimetype, with is_date set. */ +struct icaltimetype icaltime_today(void) +{ + return icaltime_from_timet_with_zone (time (NULL), 1, NULL); +} + + /* Structure used by set_tz to hold an old value of TZ, and the new value, which is in memory we will have to free in unset_tz */ /* This will hold the last "TZ=XXX" string we used with putenv(). After we @@ -228,7 +245,8 @@ time_t icaltime_as_timet_with_zone(struct icaltimetype tt, icaltimezone *zone) } /* Use our timezone functions to convert to UTC. */ - icaltimezone_convert_time (&tt, zone, utc_zone); + if (!tt.is_date) + icaltimezone_convert_time (&tt, zone, utc_zone); /* Copy the icaltimetype to a struct tm. */ memset (&stm, 0, sizeof (struct tm)); @@ -529,42 +547,70 @@ int icaltime_is_null_time(struct icaltimetype t) } -int icaltime_compare(struct icaltimetype a,struct icaltimetype b) +int icaltime_compare(struct icaltimetype a, struct icaltimetype b) { - time_t t1 = icaltime_as_timet(a); - time_t t2 = icaltime_as_timet(b); - - if (t1 > t2) { - return 1; - } else if (t1 < t2) { - return -1; - } else { - return 0; - } - + int retval; + + if (a.year > b.year) + retval = 1; + else if (a.year < b.year) + retval = -1; + + else if (a.month > b.month) + retval = 1; + else if (a.month < b.month) + retval = -1; + + else if (a.day > b.day) + retval = 1; + else if (a.day < b.day) + retval = -1; + + else if (a.hour > b.hour) + retval = 1; + else if (a.hour < b.hour) + retval = -1; + + else if (a.minute > b.minute) + retval = 1; + else if (a.minute < b.minute) + retval = -1; + + else if (a.second > b.second) + retval = 1; + else if (a.second < b.second) + retval = -1; + + else + retval = 0; + + return retval; } int icaltime_compare_date_only (struct icaltimetype a, struct icaltimetype b) { - time_t t1; - time_t t2; - - if (a.year == b.year && a.month == b.month && a.day == b.day) - return 0; - - t1 = icaltime_as_timet (a); - t2 = icaltime_as_timet (b); - - if (t1 > t2) - return 1; - else if (t1 < t2) - return -1; - else { - /* not reached */ - assert (0); - return 0; - } + int retval; + + if (a.year > b.year) + retval = 1; + else if (a.year < b.year) + retval = -1; + + else if (a.month > b.month) + retval = 1; + else if (a.month < b.month) + retval = -1; + + else if (a.day > b.day) + retval = 1; + else if (a.day < b.day) + retval = -1; + + else + retval = 0; + + return retval; } /* These are defined in icalduration.c: diff --git a/libical/src/libical/icaltime.h b/libical/src/libical/icaltime.h index ef3d65d030..b2a536b2b5 100644 --- a/libical/src/libical/icaltime.h +++ b/libical/src/libical/icaltime.h @@ -71,6 +71,12 @@ struct icaltimetype icaltime_from_timet(time_t v, int is_date); struct icaltimetype icaltime_from_timet_with_zone(time_t tm, int is_date, icaltimezone *zone); +/* Returns the current time in the given timezone, as an icaltimetype. */ +struct icaltimetype icaltime_current_time_with_zone(icaltimezone *zone); + +/* Returns the current day as an icaltimetype, with is_date set. */ +struct icaltimetype icaltime_today(void); + /* Return the time as seconds past the UNIX epoch */ time_t icaltime_as_timet(struct icaltimetype); diff --git a/libical/src/libical/icaltimezone.c b/libical/src/libical/icaltimezone.c index 5ad77e4171..bf66fcd5d1 100644 --- a/libical/src/libical/icaltimezone.c +++ b/libical/src/libical/icaltimezone.c @@ -727,8 +727,9 @@ icaltimezone_convert_time (struct icaltimetype *tt, { int utc_offset, is_daylight; - /* If both timezones are the same, we don't need to do anything. */ - if (from_zone == to_zone) + /* If the time is a DATE value or both timezones are the same, we don't + need to do anything. */ + if (tt->is_date || from_zone == to_zone) return; /* Convert the time to UTC by getting the UTC offset and subtracting it. */ |