Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/Services/Calendar/Util/ICalTime.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Calendar.Util {
* For floating times, returns the local timezone.
* Dates (with no time component) are considered floating.
*/
public GLib.TimeZone icaltime_get_timezone (ICal.Time date) {
public GLib.TimeZone icaltime_get_timezone (ICal.Time date) throws Error {
// Special case: dates are floating, so return local time zone
if (date.is_date ()) {
return new GLib.TimeZone.local ();
Expand All @@ -54,11 +54,11 @@ namespace Calendar.Util {
if (tzid.has_prefix (LIBICAL_TZ_PREFIX)) {
// TZID has prefix "/freeassociation.sourceforge.net/",
// indicating a libical TZID.
return new GLib.TimeZone (tzid.offset (LIBICAL_TZ_PREFIX.length));
return new GLib.TimeZone.identifier (tzid.offset (LIBICAL_TZ_PREFIX.length));
} else {
// TZID does not have libical prefix, potentially indicating an Olson
// standard city name.
return new GLib.TimeZone (tzid);
return new GLib.TimeZone.identifier (tzid);
}
}

Expand Down
75 changes: 48 additions & 27 deletions core/Tests/util-tests.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ void test_timezone_expected (DateTime time, ICal.Time ical,
assert_true (ical.get_tzid () != null);
}

var util_timezone = Calendar.Util.icaltime_get_timezone (ical);
var abbreviation = get_glib_tzid (util_timezone, time);
debug (@"Resulting GLib.TimeZone: $abbreviation");
assert_true (abbreviation == asserted_abbreviation);
assert_true (get_glib_offset (util_timezone, time) == get_glib_offset (asserted_zone, time));
try {
var util_timezone = Calendar.Util.icaltime_get_timezone (ical);
var abbreviation = get_glib_tzid (util_timezone, time);
debug (@"Resulting GLib.TimeZone: $abbreviation");
assert_true (abbreviation == asserted_abbreviation);
assert_true (get_glib_offset (util_timezone, time) == get_glib_offset (asserted_zone, time));
} catch (Error e) {
assert_no_error (e);
}
}

void test_floating () {
Expand All @@ -74,15 +78,20 @@ void test_sample_offsets (string tzid, string abbreviation) {
// Setup basic time info
var test_date = new GLib.DateTime.utc (2019, 11, 21, 9, 20, 0);
var iso_string = test_date.format ("%FT%TZ");
var asserted_zone = new GLib.TimeZone (tzid);
unowned ICal.Timezone ical_tz = ICal.Timezone.get_builtin_timezone (tzid);
assert_true (ical_tz != null);

// Convert to a timezone to test
var ical = new ICal.Time.from_string (iso_string).convert_to_zone (ical_tz);
var converted_gtime = test_date.to_timezone (asserted_zone);
try {
var asserted_zone = new GLib.TimeZone.identifier (tzid);
unowned ICal.Timezone ical_tz = ICal.Timezone.get_builtin_timezone (tzid);
assert_true (ical_tz != null);

// Convert to a timezone to test
var ical = new ICal.Time.from_string (iso_string).convert_to_zone (ical_tz);
var converted_gtime = test_date.to_timezone (asserted_zone);

test_timezone_expected (converted_gtime, ical, false, asserted_zone, abbreviation);
test_timezone_expected (converted_gtime, ical, false, asserted_zone, abbreviation);
} catch (Error e) {
assert_no_error (e);
}
}

// Test identifying a standard hour timezone (UTC offset is a complete hour)
Expand Down Expand Up @@ -251,13 +260,17 @@ void test_get_datetimes_all_day () {
assert_true (g_dtstart.format ("%FT%T%z") == "2019-11-21T00:00:00-0600");
assert_true (g_dtend.format ("%FT%T%z") == "2019-11-22T00:00:00-0600");

// Check the timezone
// Floating timezones (implicit in DATE-type) should get the local timezone
// when converted to GLib.
var util_timezone = Calendar.Util.icaltime_get_timezone (dtstart);
var abbreviation = get_glib_tzid (util_timezone, g_dtstart);
debug (@"Resulting timezone: $abbreviation");
assert_true (abbreviation == "CST");
try {
// Check the timezone
// Floating timezones (implicit in DATE-type) should get the local timezone
// when converted to GLib.
var util_timezone = Calendar.Util.icaltime_get_timezone (dtstart);
var abbreviation = get_glib_tzid (util_timezone, g_dtstart);
debug (@"Resulting timezone: $abbreviation");
assert_true (abbreviation == "CST");
} catch (Error e) {
assert_no_error (e);
}

// Floating timezone: converted to local should be same as not converted
Calendar.Util.icalcomponent_get_datetimes (event, out g_dtstart, out g_dtend);
Expand Down Expand Up @@ -297,11 +310,15 @@ void test_get_datetimes_not_all_day_local () {
assert_true (g_dtstart.format ("%FT%T%z") == "2019-11-21T04:20:00-0600");
assert_true (g_dtend.format ("%FT%T%z") == "2019-11-22T04:20:00-0600");

// Check the timezone
var util_timezone = Calendar.Util.icaltime_get_timezone (dtstart);
var abbreviation = get_glib_tzid (util_timezone, g_dtstart);
debug (@"Resulting timezone: $abbreviation");
assert_true (abbreviation == "CST");
try {
// Check the timezone
var util_timezone = Calendar.Util.icaltime_get_timezone (dtstart);
var abbreviation = get_glib_tzid (util_timezone, g_dtstart);
debug (@"Resulting timezone: $abbreviation");
assert_true (abbreviation == "CST");
} catch (Error e) {
assert_no_error (e);
}

Calendar.Util.icalcomponent_get_datetimes (event, out g_dtstart, out g_dtend);
assert_true (g_dtstart.format ("%FT%T%z") == "2019-11-21T04:20:00-0600");
Expand Down Expand Up @@ -364,9 +381,13 @@ void test_get_datetimes_not_all_day_floating () {
var dtstart = event.get_dtstart ();
assert_true (!dtstart.is_date ());

var util_timezone = Calendar.Util.icaltime_get_timezone (dtstart);
var abbreviation = util_timezone.get_abbreviation (0);
debug (@"Resulting timezone: $abbreviation");
try {
var util_timezone = Calendar.Util.icaltime_get_timezone (dtstart);
var abbreviation = util_timezone.get_abbreviation (0);
debug (@"Resulting timezone: $abbreviation");
} catch (Error e) {
assert_no_error (e);
}

DateTime g_dtstart,g_dtend;
Calendar.Util.icalcomponent_get_local_datetimes (event, out g_dtstart, out g_dtend);
Expand Down