diff --git a/src/libical/icaltime.c b/src/libical/icaltime.c index b6247d56..addd7fb7 100644 --- a/src/libical/icaltime.c +++ b/src/libical/icaltime.c @@ -207,6 +207,8 @@ struct icaltimetype icaltime_from_timet_with_zone(const time_t tm, const int is_ icaltimezone_convert_time(&tt, utc_zone, (icaltimezone *) zone); tt.is_date = is_date; + if(zone) + tt.zone = zone; /* If it is a DATE value, make sure hour, minute & second are 0. */ if (is_date) { @@ -279,7 +281,8 @@ time_t icaltime_as_timet_with_zone(const struct icaltimetype tt, const icaltimez local_tt.is_date = 0; /* Use our timezone functions to convert to UTC. */ - icaltimezone_convert_time(&local_tt, (icaltimezone *) zone, utc_zone); + if (tt.zone != utc_zone) + icaltimezone_convert_time(&local_tt, (icaltimezone *) zone, utc_zone); /* Copy the icaltimetype to a struct tm. */ memset(&stm, 0, sizeof(struct tm)); diff --git a/src/test/regression.c b/src/test/regression.c index 0e25b121..245230a3 100644 --- a/src/test/regression.c +++ b/src/test/regression.c @@ -4945,6 +4945,26 @@ static void test_remove_tzid_from_due(void) icalcomponent_free(c); } +static void test_icaltime_proper_zone(void) +{ + icaltimetype first, second; + icaltimezone *utc = icaltimezone_get_utc_timezone(); + icaltimezone *first_zone = icaltimezone_get_builtin_timezone("Europe/Brussels"); + icaltimezone *second_zone = icaltimezone_get_builtin_timezone("America/New_York"); + + first = icaltime_current_time_with_zone(first_zone); + ok("first::zone is not NULL", (icaltime_get_timezone(first) != NULL)); + ok("first::zone is not UTC", (icaltime_get_timezone(first) != utc)); + ok("first::zone preserves zone", (icaltime_get_timezone(first) == first_zone)); + + second = icaltime_current_time_with_zone(second_zone); + ok("second::zone is not NULL", (icaltime_get_timezone(second) != NULL)); + ok("second::zone is not UTC", (icaltime_get_timezone(second) != utc)); + ok("second::zone preserves zone", (icaltime_get_timezone(second) == second_zone)); + + ok("first is before or same with the second", (icaltime_compare(first, second) <= 0)); +} + int main(int argc, char *argv[]) { #if !defined(HAVE_UNISTD_H) @@ -5087,6 +5107,7 @@ int main(int argc, char *argv[]) test_run("Test implicit DTEND and DURATION for VEVENT and VTODO", test_implicit_dtend_duration, do_test, do_header); test_run("Test icalvalue resets timezone on set", test_icalvalue_resets_timezone_on_set, do_test, do_header); test_run("Test removing TZID from DUE with icalcomponent_set_due", test_remove_tzid_from_due, do_test, do_header); + test_run("Test icaltime proper zone set", test_icaltime_proper_zone, do_test, do_header); /** OPTIONAL TESTS go here... **/