year-view: Fix for 01-01-2017 date
Previous fix was considering Jan 1st and Dec 31st to find the week number, using ISO 8601 standard, and that was causing an issue with some dates like Jan 1st, 2017 which was displaying week# 52 instead of week #1. The issue happened because ISO 8601 always consider Monday as the first weekday, so as Jan 1st, 2017 is a Sunday, it' still considered week# 52 and not week# 1. After checking GtkCalendar code I noticed it uses the same ISO 8601 standard but instead of using Jan 1st or Dec 31st, it always get the week number based on the last day of that week, taking account if the week starts on Sunday or Monday, depending on the locale. In our example, using a calendar based on Sunday, Jan 1st, 2017 is the first day of the week and Jan 7th, 2017 is the last one. Therefore I changed week number code to always use the last day of the week. https://bugzilla.gnome.org/show_bug.cgi?id=757622
This commit is contained in:
committed by
Georges Basile Stavracas Neto
parent
f4d015759d
commit
9646d4f543
+25
-7
@@ -119,6 +119,26 @@ G_DEFINE_TYPE_WITH_CODE (GcalYearView, gcal_year_view, GTK_TYPE_BOX,
|
||||
G_IMPLEMENT_INTERFACE (E_TYPE_CAL_DATA_MODEL_SUBSCRIBER,
|
||||
gcal_data_model_subscriber_interface_init));
|
||||
|
||||
static guint
|
||||
get_last_week_of_year_dmy (gint first_weekday,
|
||||
GDateDay day,
|
||||
GDateMonth month,
|
||||
GDateYear year)
|
||||
{
|
||||
GDate day_of_year;
|
||||
gint day_of_week;
|
||||
|
||||
g_date_set_dmy (&day_of_year, day, month, year);
|
||||
day_of_week = g_date_get_weekday (&day_of_year) % 7;
|
||||
|
||||
if (day_of_week >= first_weekday)
|
||||
g_date_add_days (&day_of_year, (6 - day_of_week) + first_weekday);
|
||||
else
|
||||
g_date_add_days (&day_of_year, first_weekday - day_of_week - 1);
|
||||
|
||||
return g_date_get_iso8601_week_of_year (&day_of_year);
|
||||
}
|
||||
|
||||
static void
|
||||
update_date (GcalYearView *year_view,
|
||||
icaltimetype *new_date)
|
||||
@@ -128,6 +148,11 @@ update_date (GcalYearView *year_view,
|
||||
|
||||
g_clear_pointer (&year_view->date, g_free);
|
||||
year_view->date = new_date;
|
||||
|
||||
year_view->first_week_of_year = get_last_week_of_year_dmy (year_view->first_weekday,
|
||||
1, G_DATE_JANUARY, year_view->date->year);;
|
||||
year_view->last_week_of_year = get_last_week_of_year_dmy (year_view->first_weekday,
|
||||
31, G_DATE_DECEMBER, year_view->date->year);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -793,7 +818,6 @@ 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;
|
||||
|
||||
@@ -844,12 +868,6 @@ draw_navigator (GcalYearView *year_view,
|
||||
real_padding_top = (height - (7 * 3 * box_side)) / 4.0;
|
||||
|
||||
year_view->navigator_grid->box_side = box_side;
|
||||
|
||||
/* get first and last weeks of the year */
|
||||
g_date_set_dmy (&day_of_year, 1, G_DATE_JANUARY, year_view->date->year);
|
||||
year_view->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, year_view->date->year);
|
||||
year_view->last_week_of_year = g_date_get_iso8601_week_of_year (&day_of_year);
|
||||
weeks_counter = year_view->first_week_of_year;
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user