Skip to content

Commit

Permalink
Utils: Use GLib.Timezone.identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypw authored and tintou committed Sep 16, 2024
1 parent 52d33a0 commit 4a9c060
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/Util.vala
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,18 @@ namespace Tasks.Util {
* will always return a GLib.TimeZone, which will be UTC if parsing
* fails for some reason.
*/
var prefix = "/freeassociation.sourceforge.net/";
if (tzid.has_prefix (prefix)) {
// TZID has prefix "/freeassociation.sourceforge.net/",
// indicating a libical TZID.
return new GLib.TimeZone (tzid.offset (prefix.length));
} else {
// TZID does not have libical prefix, potentially indicating an Olson
// standard city name.
return new GLib.TimeZone (tzid);
}
try {
var prefix = "/freeassociation.sourceforge.net/";
if (tzid.has_prefix (prefix)) {
// TZID has prefix "/freeassociation.sourceforge.net/",
// indicating a libical TZID.
return new GLib.TimeZone.identifier (tzid.offset (prefix.length));
} else {
// TZID does not have libical prefix, potentially indicating an Olson
// standard city name.
return new GLib.TimeZone.identifier (tzid);
}
} catch (Error e) {} // Fall through code deals with error
}
// If tzid fails, try ICal.Time.get_timezone ()
unowned ICal.Timezone? timezone = null;
Expand All @@ -191,7 +193,11 @@ namespace Tasks.Util {
var minutes = (interval % 3600) / 60;
var hour_string = "%s%02d:%02d".printf (is_positive ? "+" : "-", hours, minutes);

return new GLib.TimeZone (hour_string);
try {
return new GLib.TimeZone.identifier (hour_string);
} catch (Error e) {
return new GLib.TimeZone.local ();
}
}

/**
Expand Down

0 comments on commit 4a9c060

Please sign in to comment.