[gnome-calendar] gnome-calendar: Fix week #s in year view



commit c4853dd855f0412a01832b12c9ed4098fe822486
Author: Isaque Galdino <igaldino gmail com>
Date:   Tue Jan 19 01:00:10 2016 -0200

    gnome-calendar: Fix week #s in year view
    
    Changed year view to use ISO 8601 standard to display the week #s
    correctly when showing first and last weeks.
    
    Year view was always starting week #s as 1, based on Jan 1st, and it
    kept count the weeks until Dec 31st. But according to ISO 8601 standard,
    that's not always true, i.e. Jan 1st 2016, is still in the 53th week of
    2015, while Dec 31st 2014 is already in the 1st week of 2015.
    
    Now the code is using ISO 8601 GDate function to get the correct week
    number for the first and the last weeks of the year only. Other weeks
    continue to use the same logic.
    
    More about ISO 6801: https://en.wikipedia.org/wiki/ISO_8601#Week_dates
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757622

 src/gcal-year-view.c |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/src/gcal-year-view.c b/src/gcal-year-view.c
index fdfff87..21d4008 100644
--- a/src/gcal-year-view.c
+++ b/src/gcal-year-view.c
@@ -74,7 +74,11 @@ struct _GcalYearViewPrivate
    * 0 for Sunday, 1 for Monday and so on */
   gint          first_weekday;
 
-  /**
+  /* first and last weeks of the year */
+  guint         first_week_of_year;
+  guint         last_week_of_year;
+
+    /**
    * clock format from GNOME desktop settings
    */
   gboolean      use_24h_format;
@@ -719,9 +723,15 @@ draw_month_grid (GcalYearView *year_view,
 
   for (i = 0; i < shown_rows; i++)
     {
-      if (i == 0)
+      /* special condition for first and last weeks of the year */
+      if (month_nr == 0 && priv->first_week_of_year > 1 && i == 1)
+        *weeks_counter = 1;
+      else if (month_nr == 11 && (i + 1) == shown_rows)
+        *weeks_counter = priv->last_week_of_year;
+      /* other weeks */
+      else if (i == 0)
         {
-          if (days_delay == 0)
+          if (days_delay == 0 && month_nr != 0)
             *weeks_counter = *weeks_counter + 1;
         }
       else
@@ -764,6 +774,7 @@ draw_navigator (GcalYearView *year_view,
   gint header_padding_left, header_padding_top, header_height, layout_width, layout_height;
   gint real_padding_left, real_padding_top, i, sw, weeks_counter;
   gdouble width, height, box_side;
+  GDate day_of_year;
 
   gchar *header_str;
 
@@ -815,7 +826,13 @@ draw_navigator (GcalYearView *year_view,
   real_padding_top = (height - (7 * 3 * box_side)) / 4.0;
 
   priv->navigator_grid->box_side = box_side;
-  weeks_counter = 1;
+
+  /* get first and last weeks of the year */
+  g_date_set_dmy (&day_of_year, 1, G_DATE_JANUARY, priv->date->year);
+  priv->first_week_of_year = g_date_get_iso8601_week_of_year (&day_of_year);
+  g_date_set_dmy (&day_of_year, 31, G_DATE_DECEMBER, priv->date->year);
+  priv->last_week_of_year = g_date_get_iso8601_week_of_year (&day_of_year);
+  weeks_counter = priv->first_week_of_year;
   for (i = 0; i < 12; i++)
     {
       gint row = i / 4;


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