week-view: set correct week number

In this commit, the correct week number is set in week-view.

The problem is, the week number of week-view is being set according to
the first day of the week (if the first and last day of the week
are in the same year), or the first and last day of the week
(if the first and last day are in different years).

To fix this, the week number is being set according to the middle day
of the week (according to ISO 8601 standards), resulting in correct
week numbers.

https://bugzilla.gnome.org/show_bug.cgi?id=779331
This commit is contained in:
Joyjit Choudhury
2017-03-16 20:31:37 -03:00
committed by Georges Basile Stavracas Neto
parent 0266202d40
commit 35b2f90cab
+5 -5
View File
@@ -845,7 +845,7 @@ update_unchanged_events (GcalWeekHeader *self,
static void
update_title (GcalWeekHeader *self)
{
GDateTime *week_start, *week_end;
GDateTime *week_start, *week_end, *week_mid;
gchar *year_label, *month_label, *week_label;
if(!self->active_date)
@@ -853,6 +853,7 @@ update_title (GcalWeekHeader *self)
week_start = get_start_of_week (self->active_date);
week_end = g_date_time_add_days (week_start, 6);
week_mid = g_date_time_add_days (week_start, 3);
if (g_date_time_get_month (week_start) == g_date_time_get_month (week_end))
{
@@ -867,25 +868,24 @@ update_title (GcalWeekHeader *self)
if (g_date_time_get_year (week_start) == g_date_time_get_year (week_end))
{
week_label = g_strdup_printf (_("week %d"), g_date_time_get_week_of_year (week_start));
year_label = g_strdup_printf ("%d", g_date_time_get_year (week_start));
}
else
{
week_label = g_strdup_printf (_("week %d / %d"),
g_date_time_get_week_of_year (week_start),
g_date_time_get_week_of_year (week_end));
year_label = g_strdup_printf ("%d - %d",
g_date_time_get_year (week_start),
g_date_time_get_year (week_end));
}
week_label = g_strdup_printf (_("week %d"), g_date_time_get_week_of_year (week_mid));
gtk_label_set_label (GTK_LABEL (self->month_label), month_label);
gtk_label_set_label (GTK_LABEL (self->week_label), week_label);
gtk_label_set_label (GTK_LABEL (self->year_label), year_label);
g_clear_pointer (&week_start, g_date_time_unref);
g_clear_pointer (&week_end, g_date_time_unref);
g_clear_pointer (&week_mid, g_date_time_unref);
g_clear_pointer (&month_label, g_free);
g_clear_pointer (&week_label, g_free);
g_clear_pointer (&year_label, g_free);