aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2009-10-16 18:20:30 +0800
committerMilan Crha <mcrha@redhat.com>2009-10-16 18:20:30 +0800
commita500783aca7da027c8c1898cb5d55ebdb2c04e85 (patch)
treebdb7e527ed8491d71a615f8bf4f5e8d72551ec33 /widgets
parentbe17ff02ab1ab6560ba49981b3536fa67ff73d07 (diff)
downloadgsoc2013-evolution-a500783aca7da027c8c1898cb5d55ebdb2c04e85.tar
gsoc2013-evolution-a500783aca7da027c8c1898cb5d55ebdb2c04e85.tar.gz
gsoc2013-evolution-a500783aca7da027c8c1898cb5d55ebdb2c04e85.tar.bz2
gsoc2013-evolution-a500783aca7da027c8c1898cb5d55ebdb2c04e85.tar.lz
gsoc2013-evolution-a500783aca7da027c8c1898cb5d55ebdb2c04e85.tar.xz
gsoc2013-evolution-a500783aca7da027c8c1898cb5d55ebdb2c04e85.tar.zst
gsoc2013-evolution-a500783aca7da027c8c1898cb5d55ebdb2c04e85.zip
Bug #267749 - Week numbers are incorrect when the week starts on Sunday
Diffstat (limited to 'widgets')
-rw-r--r--widgets/misc/e-calendar-item.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/widgets/misc/e-calendar-item.c b/widgets/misc/e-calendar-item.c
index 41b5eea6ca..8d879b1826 100644
--- a/widgets/misc/e-calendar-item.c
+++ b/widgets/misc/e-calendar-item.c
@@ -1715,9 +1715,7 @@ e_calendar_item_get_week_number (ECalendarItem *calitem,
{
GDate date;
guint weekday, yearday;
- gint offset, week_num;
-
- /* FIXME: check what happens at year boundaries. */
+ gint week_num;
g_date_clear (&date, 1);
g_date_set_dmy (&date, day, month + 1, year);
@@ -1725,24 +1723,31 @@ e_calendar_item_get_week_number (ECalendarItem *calitem,
/* This results in a value of 0 (Monday) - 6 (Sunday). (or -1 on error - oops!!) */
weekday = g_date_get_weekday (&date) - 1;
- /* Calculate the offset from the start of the week. */
- offset = (calitem->week_start_day + 7 - weekday) % 7;
+ if (weekday > 0) {
+ /* we want always point to nearest Monday, as the first day of the week,
+ regardless of the calendar's week_start_day */
+ if (weekday >= 3)
+ g_date_add_days (&date, 7 - weekday);
+ else
+ g_date_subtract_days (&date, weekday);
+
+ weekday = g_date_get_weekday (&date) - 1;
+ }
/* Calculate the day of the year, from 0 to 365. */
yearday = g_date_get_day_of_year (&date) - 1;
/* If the week starts on or after 29th December, it is week 1 of the
next year, since there are 4 days in the next year. */
- g_date_subtract_days (&date, offset);
if (g_date_get_month (&date) == 12 && g_date_get_day (&date) >= 29)
return 1;
/* Calculate the week number, from 0. */
- week_num = (yearday - offset) / 7;
+ week_num = yearday / 7;
/* If the first week starts on or after Jan 5th, then we need to add
1 since the previous week will really be the first week. */
- if ((yearday - offset) % 7 >= 4)
+ if (yearday % 7 >= 4)
week_num++;
/* Add 1 so week numbers are from 1 to 53. */