[california/wip/timezone] GLib.TimeZone -> Calendar.Timezone



commit dc786c6cdaeb10b5394ee7a474229d17ccd3e51b
Author: Jim Nelson <jim yorba org>
Date:   Thu Mar 6 17:41:17 2014 -0800

    GLib.TimeZone -> Calendar.Timezone

 src/calendar/calendar-date.vala            |   13 ++++++-----
 src/calendar/calendar-exact-time-span.vala |    8 +++---
 src/calendar/calendar-exact-time.vala      |   29 ++++++++++++++-------------
 src/calendar/calendar-span.vala            |    4 +-
 src/calendar/calendar-system.vala          |    6 ++--
 src/calendar/calendar-timezone.vala        |   12 +++++++++-
 src/component/component-date-time.vala     |   20 +++++++++---------
 src/host/host-create-update-event.vala     |    5 ++-
 src/host/host-show-event.vala              |    2 +-
 src/view/month/month-cell.vala             |    8 ++----
 src/view/month/month-controllable.vala     |    6 ++--
 11 files changed, 61 insertions(+), 52 deletions(-)
---
diff --git a/src/calendar/calendar-date.vala b/src/calendar/calendar-date.vala
index c04d27e..a401342 100644
--- a/src/calendar/calendar-date.vala
+++ b/src/calendar/calendar-date.vala
@@ -78,9 +78,9 @@ public class Date : BaseObject, Gee.Comparable<Date>, Gee.Hashable<Date> {
     }
     
     /**
-     * Creates a { link Date} that corresponds to the current time in the specified timezone.
+     * Creates a { link Date} that corresponds to the current time in the specified { link Timezone}.
      */
-    public Date.now(TimeZone tz) {
+    public Date.now(Timezone tz) {
         this.from_exact_time(new ExactTime.now(tz));
     }
     
@@ -160,22 +160,23 @@ public class Date : BaseObject, Gee.Comparable<Date>, Gee.Hashable<Date> {
     }
     
     /**
-     * Returns the { link Date} as the earliest ExactTime possible for the specified TimeZone.
+     * Returns the { link Date} as the earliest ExactTime possible for the specified { link Timezone}.
      *
      * @see latest_exact_time
      */
-    public ExactTime earliest_exact_time(TimeZone tz) {
+    public ExactTime earliest_exact_time(Timezone tz) {
         return new ExactTime(tz, this, WallTime.earliest);
     }
     
     /**
-     * Returns the { link Date} as the latest { link ExactTime} possible for the specified TimeZone.
+     * Returns the { link Date} as the latest { link ExactTime} possible for the specified
+     * { link Timezone}.
      *
      * By latest, the precision of ExactTime.seconds will be 59.0.
      *
      * @see earliest_exact_time
      */
-    public ExactTime latest_exact_time(TimeZone tz) {
+    public ExactTime latest_exact_time(Timezone tz) {
         return new ExactTime(tz, this, WallTime.latest);
     }
     
diff --git a/src/calendar/calendar-exact-time-span.vala b/src/calendar/calendar-exact-time-span.vala
index 002addc..ec58fa7 100644
--- a/src/calendar/calendar-exact-time-span.vala
+++ b/src/calendar/calendar-exact-time-span.vala
@@ -11,7 +11,7 @@ namespace California.Calendar {
  *
  * This is conceptually similar to { link DateSpan}, but (currently) doesn't allow for iteration.
  *
- * Note that there's no checking for matching TimeZones; in the future, these times may be
+ * Note that there's no checking for matching Timezones; in the future, these times may be
  * normalized to UTC.
  */
 
@@ -62,7 +62,7 @@ public class ExactTimeSpan : BaseObject, Gee.Comparable<ExactTimeSpan>, Gee.Hash
         end_date = new Date.from_exact_time(end_exact_time);
     }
     
-    public ExactTimeSpan.from_date_span(DateSpan span, TimeZone tz) {
+    public ExactTimeSpan.from_date_span(DateSpan span, Timezone tz) {
         this (span.earliest_exact_time(tz), span.latest_exact_time(tz));
     }
     
@@ -75,9 +75,9 @@ public class ExactTimeSpan : BaseObject, Gee.Comparable<ExactTimeSpan>, Gee.Hash
     
     /**
      * Returns a new { link ExactTimeSpan} with both { link start_date_time} and
-     * { link end_date_time} converted to the supplied TimeZone.
+     * { link end_date_time} converted to the supplied { link Timezone}.
      */
-    public ExactTimeSpan to_timezone(TimeZone new_tz) {
+    public ExactTimeSpan to_timezone(Timezone new_tz) {
         return new ExactTimeSpan(start_exact_time.to_timezone(new_tz),
             end_exact_time.to_timezone(new_tz));
     }
diff --git a/src/calendar/calendar-exact-time.vala b/src/calendar/calendar-exact-time.vala
index 0f9388e..74078cd 100644
--- a/src/calendar/calendar-exact-time.vala
+++ b/src/calendar/calendar-exact-time.vala
@@ -10,7 +10,8 @@ namespace California.Calendar {
  * An immutable representation of an exact moment of time on a particular calendar day.
  *
  * This uses GLib's DateTime class but adds some extra logic useful to California, including
- * storing the TimeZone used to generate the DateTime and making this object work well with Gee.
+ * storing the { link Timezone} used to generate the DateTime and making this object work well with
+ * Gee.
  *
  * "Exact" is limited, of course, to the precision of DateTime, but it's close enough for our needs.
  */
@@ -41,16 +42,16 @@ public class ExactTime : BaseObject, Gee.Comparable<ExactTime>, Gee.Hashable<Exa
     public bool is_dst { get { return date_time.is_daylight_savings(); } }
     
     /**
-     * The timezone used to generate this moment of time.
+     * The { link Timezone} used to generate this moment of time.
      *
      * @see to_timezone
      */
-    public TimeZone tz { get; private set; }
+    public Timezone tz { get; private set; }
     
     /**
-     * The TZID for the current time's timezone.
+     * A human-oriented string representing the current time's time zone as an abbreviation.
      *
-     * TZID is (generally) three-letter acronyms, i.e. "PST" for Pacific Standard Time.
+     * This value should ''not'' be used to generate an { link OlsonZone}.
      *
      * @see tz
      */
@@ -63,7 +64,7 @@ public class ExactTime : BaseObject, Gee.Comparable<ExactTime>, Gee.Hashable<Exa
     
     private DateTime date_time;
     
-    public ExactTime(TimeZone tz, Date date, WallTime time) {
+    public ExactTime(Timezone tz, Date date, WallTime time) {
         try {
             init(tz, date.year.value, date.month.value, date.day_of_month.value,
                 time.hour, time.minute, time.second);
@@ -73,26 +74,26 @@ public class ExactTime : BaseObject, Gee.Comparable<ExactTime>, Gee.Hashable<Exa
         }
     }
     
-    public ExactTime.full(TimeZone tz, int year, int month, int day, int hour, int minute,
+    public ExactTime.full(Timezone tz, int year, int month, int day, int hour, int minute,
         double second) throws CalendarError {
         init(tz, year, month, day, hour, minute, second);
     }
     
-    public ExactTime.now(TimeZone tz) {
-        date_time = new DateTime.now(tz);
+    public ExactTime.now(Timezone tz) {
+        date_time = new DateTime.now(tz.time_zone);
         if (date_time == null)
             error("DateTime.now failed");
         this.tz = tz;
     }
     
-    public ExactTime.from_date_time(DateTime date_time, TimeZone tz) {
+    public ExactTime.from_date_time(DateTime date_time, Timezone tz) {
         this.date_time = date_time;
         this.tz = tz;
     }
     
-    private void init(TimeZone tz, int year, int month, int day, int hour, int minute, double second)
+    private void init(Timezone tz, int year, int month, int day, int hour, int minute, double second)
         throws CalendarError {
-        date_time = new DateTime(tz, year, month, day, hour, minute, second);
+        date_time = new DateTime(tz.time_zone, year, month, day, hour, minute, second);
         if (date_time == null) {
             throw new CalendarError.INVALID("Invalid specified DateTime: %02d/%02d/%d %02d:%02d:%02lf",
                 day, month, year, hour, minute, second);
@@ -161,8 +162,8 @@ public class ExactTime : BaseObject, Gee.Comparable<ExactTime>, Gee.Hashable<Exa
     /**
      * See DateTime.to_timezone.
      */
-    public ExactTime to_timezone(TimeZone new_tz) {
-        return new ExactTime.from_date_time(date_time.to_timezone(new_tz), new_tz);
+    public ExactTime to_timezone(Timezone new_tz) {
+        return new ExactTime.from_date_time(date_time.to_timezone(new_tz.time_zone), new_tz);
     }
     
     /**
diff --git a/src/calendar/calendar-span.vala b/src/calendar/calendar-span.vala
index f8cfe37..187bd88 100644
--- a/src/calendar/calendar-span.vala
+++ b/src/calendar/calendar-span.vala
@@ -52,7 +52,7 @@ public interface Span<G> : BaseObject, Collection.SimpleIterable<G> {
      *
      * @see Date.earliest_exact_time
      */
-    public ExactTime earliest_exact_time(TimeZone tz) {
+    public ExactTime earliest_exact_time(Timezone tz) {
         return start_date.earliest_exact_time(tz);
     }
     
@@ -61,7 +61,7 @@ public interface Span<G> : BaseObject, Collection.SimpleIterable<G> {
      *
      * @see Date.latest_exact_time
      */
-    public ExactTime latest_exact_time(TimeZone tz) {
+    public ExactTime latest_exact_time(Timezone tz) {
         return end_date.latest_exact_time(tz);
     }
     
diff --git a/src/calendar/calendar-system.vala b/src/calendar/calendar-system.vala
index a75d02e..446fd22 100644
--- a/src/calendar/calendar-system.vala
+++ b/src/calendar/calendar-system.vala
@@ -26,11 +26,11 @@ public class System : BaseObject {
     public static Date today { get; private set; }
     
     /**
-     * Returns the current { link ExactTime} of the local TimeZone.
+     * Returns the current { link ExactTime} of the local { link Timezone}.
      */
     public static ExactTime now {
         owned get {
-            return new ExactTime.now(new TimeZone.local());
+            return new ExactTime.now(Timezone.local);
         }
     }
     
@@ -80,7 +80,7 @@ public class System : BaseObject {
         is_24hr = false;
         
         // TODO: Tie this into the event loop so it's properly updated
-        today = new Date.now(new TimeZone.local());
+        today = new Date.now(Timezone.local);
     }
     
     internal static void preinit() throws IOError {
diff --git a/src/calendar/calendar-timezone.vala b/src/calendar/calendar-timezone.vala
index 773997a..a1b54e1 100644
--- a/src/calendar/calendar-timezone.vala
+++ b/src/calendar/calendar-timezone.vala
@@ -6,6 +6,14 @@
 
 namespace California.Calendar {
 
+/**
+ * An immutable representation of a time zone and its associated Olson zoneinfo.
+ *
+ * Like { link ExactTime}, this class arose because GLib's TimeZone works well for many things but
+ * additional functionality needed to be added.  The most pressing need is to maintain the Olson
+ * zone information for the lifetime of the object.
+ */
+
 public class Timezone : BaseObject {
     /**
      * The { link Timezone} for UTC.
@@ -42,10 +50,10 @@ public class Timezone : BaseObject {
      */
     public bool is_local { get { return this == local; } }
     
-    private TimeZone tz;
+    internal TimeZone time_zone { get; private set; }
     
     public Timezone(OlsonZone zone) {
-        tz = new TimeZone(zone.value);
+        time_zone = new TimeZone(zone.value);
         this.zone = zone;
     }
     
diff --git a/src/component/component-date-time.vala b/src/component/component-date-time.vala
index 7c5f6e2..4a23b96 100644
--- a/src/component/component-date-time.vala
+++ b/src/component/component-date-time.vala
@@ -10,12 +10,12 @@ public class DateTime : BaseObject {
     /**
      * The TZID for the iCal component and property kind.
      *
-     * TZID in libical means Olson city timezone.  A null tzid indicates floating time or a DATE.
+     * TZID in libical means Olson city timezone.  A null zone indicates floating time or a DATE.
      *
      * @see is_floating_time
      * @see is_date
      */
-    public string? tzid { get; private set; default = null; }
+    public Calendar.OlsonZone? zone { get; private set; default = null; }
     
     /**
      * Indicates if this { link DateTime} is for UTC time.
@@ -27,7 +27,7 @@ public class DateTime : BaseObject {
      *
      * See [[https://tools.ietf.org/html/rfc5545#section-3.8.3.1]]
      */
-    public bool is_floating { get { return tzid == null && !is_date; } }
+    public bool is_floating { get { return zone == null && !is_date; } }
     
     /**
      * Indicates if this is a DATE rather than a DATE-TIME.
@@ -78,7 +78,7 @@ public class DateTime : BaseObject {
         
         unowned iCal.icalparameter? param = prop.get_first_parameter(iCal.icalparameter_kind.TZID_PARAMETER);
         if (param != null)
-            tzid = param.get_tzid();
+            zone = new Calendar.OlsonZone(param.get_tzid());
     }
     
     /**
@@ -108,22 +108,22 @@ public class DateTime : BaseObject {
     }
     
     /**
-     * Returns a TimeZone for the DATE-TIME.
+     * Returns a { link Timezone} for the DATE-TIME.
      *
      * Returns null if { link is_date} is true.  Returns the local timezone if { link is_floating}
      * is true.  Returns the timezone for UTC if { link is_utc} is true.
      */
-    public TimeZone? get_timezone() {
+    public Calendar.Timezone? get_timezone() {
         if (is_date)
             return null;
         
         if (is_utc)
-            return new TimeZone.utc();
+            return Calendar.Timezone.utc;
         
-        if (is_floating || tzid == null)
-            return new TimeZone.local();
+        if (is_floating || zone == null)
+            return Calendar.Timezone.local;
         
-        return new TimeZone(tzid);
+        return new Calendar.Timezone(zone);
     }
     
     /**
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index 503d91a..257edd7 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -237,8 +237,9 @@ public class CreateUpdateEvent : Gtk.Grid {
             event.set_event_date_span(selected_date_span);
         } else {
             // use existing timezone unless not specified in original event
-            TimeZone tz = (event.exact_time_span != null) ? event.exact_time_span.start_exact_time.tz
-                : new TimeZone.local();
+            Calendar.Timezone tz = (event.exact_time_span != null)
+                ? event.exact_time_span.start_exact_time.tz
+                : Calendar.Timezone.local;
             event.set_event_exact_time_span(
                 new Calendar.ExactTimeSpan(
                     new Calendar.ExactTime(tz, selected_date_span.start_date,
diff --git a/src/host/host-show-event.vala b/src/host/host-show-event.vala
index f6bf6d0..afb5367 100644
--- a/src/host/host-show-event.vala
+++ b/src/host/host-show-event.vala
@@ -56,7 +56,7 @@ public class ShowEvent : Gtk.Grid {
             }
         } else {
             Calendar.ExactTimeSpan exact_time_span = event.exact_time_span.to_timezone(
-                new TimeZone.local());
+                Calendar.Timezone.local);
             if (exact_time_span.is_same_day) {
                 // Single-day timed event, print "<full date>\n<full start time> to <full end time>",
                 // including year if not current year
diff --git a/src/view/month/month-cell.vala b/src/view/month/month-cell.vala
index 61ad64c..ee4bf73 100644
--- a/src/view/month/month-cell.vala
+++ b/src/view/month/month-cell.vala
@@ -207,17 +207,15 @@ public class Cell : Gtk.EventBox {
         int line_number = 0;
         line_to_event.clear();
         
-        // convert all times to local timezone
-        TimeZone local = new TimeZone.local();
-        
         // draw all events in chronological order, all-day events first, storing lookup data
-        // as the "lines" are drawn
+        // as the "lines" are drawn ... make sure to convert them all to local timezone
         foreach (Component.Event event in days_events) {
             string text;
             if (event.is_all_day) {
                 text = event.summary;
             } else {
-                Calendar.ExactTime local_start = event.exact_time_span.start_exact_time.to_timezone(local);
+                Calendar.ExactTime local_start = event.exact_time_span.start_exact_time.to_timezone(
+                    Calendar.Timezone.local);
                 text = "%s %s".printf(local_start.to_pretty_time_string(PRETTY_TIME_FLAGS), event.summary);
             }
             
diff --git a/src/view/month/month-controllable.vala b/src/view/month/month-controllable.vala
index 0572de8..5c7ed5a 100644
--- a/src/view/month/month-controllable.vala
+++ b/src/view/month/month-controllable.vala
@@ -247,7 +247,7 @@ public class Controllable : Gtk.Grid, View.Controllable {
         
         // generate new ExactTimeSpan window for all calendar subscriptions
         Calendar.ExactTimeSpan window = new Calendar.ExactTimeSpan.from_date_span(month_of_year,
-            new TimeZone.local());
+            Calendar.Timezone.local);
         
         // clear current subscriptions and generate new subscriptions for new window
         subscriptions.clear();
@@ -406,9 +406,9 @@ public class Controllable : Gtk.Grid, View.Controllable {
         // TODO: Define default time better
         Calendar.ExactTime start;
         if(release_cell.date.equal_to(Calendar.System.today)) {
-            start = new Calendar.ExactTime.now(new TimeZone.local());
+            start = new Calendar.ExactTime.now(Calendar.Timezone.local);
         } else {
-            start = new Calendar.ExactTime(new TimeZone.local(), release_cell.date,
+            start = new Calendar.ExactTime(Calendar.Timezone.local, release_cell.date,
                 new Calendar.WallTime(13, 0, 0));
         }
         


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]