[evolution] Convert all "week-start-day" properties to GDateWeekday.



commit 3b205698762afcd86ac79595960253d84aff5487
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Mar 6 20:27:31 2013 -0500

    Convert all "week-start-day" properties to GDateWeekday.

 calendar/gui/dialogs/comp-editor.c          |   19 +-
 calendar/gui/dialogs/comp-editor.h          |    4 +-
 calendar/gui/dialogs/recurrence-page.c      |  126 +++++++++++--
 calendar/gui/e-cal-model.c                  |   31 ++--
 calendar/gui/e-cal-model.h                  |    4 +-
 calendar/gui/e-day-view.c                   |    2 +-
 calendar/gui/e-week-view-layout.c           |   38 ++--
 calendar/gui/e-week-view-layout.h           |   50 +++---
 calendar/gui/e-week-view-titles-item.c      |   19 +-
 calendar/gui/e-week-view.c                  |   85 ++++++---
 calendar/gui/e-week-view.h                  |    9 +-
 calendar/gui/e-weekday-chooser.c            |  274 ++++++++++++---------------
 calendar/gui/e-weekday-chooser.h            |   22 ++-
 calendar/gui/ea-week-view-cell.c            |   37 ++--
 calendar/gui/gnome-cal.c                    |   34 ++--
 calendar/gui/print.c                        |  108 +++++++----
 e-util/e-calendar-item.c                    |  118 ++++++------
 e-util/e-calendar-item.h                    |    6 +-
 e-util/e-dateedit.c                         |   36 ++--
 e-util/e-dateedit.h                         |    6 +-
 e-util/ea-calendar-item.c                   |   10 +-
 modules/calendar/e-cal-shell-settings.c     |   63 +------
 modules/calendar/e-cal-shell-view-private.c |    7 +-
 modules/calendar/e-calendar-preferences.c   |    9 +-
 modules/calendar/e-calendar-preferences.ui  |   47 +----
 25 files changed, 616 insertions(+), 548 deletions(-)
---
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index cb7de1f..f36bebc 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -108,7 +108,7 @@ struct _CompEditorPrivate {
        icaltimezone *zone;
        gboolean use_24_hour_format;
 
-       gint week_start_day;
+       GDateWeekday week_start_day;
 
        gint work_day_end_hour;
        gint work_day_end_minute;
@@ -1428,7 +1428,7 @@ comp_editor_set_property (GObject *object,
                case PROP_WEEK_START_DAY:
                        comp_editor_set_week_start_day (
                                COMP_EDITOR (object),
-                               g_value_get_int (value));
+                               g_value_get_enum (value));
                        return;
 
                case PROP_WORK_DAY_END_HOUR:
@@ -1515,7 +1515,7 @@ comp_editor_get_property (GObject *object,
                        return;
 
                case PROP_WEEK_START_DAY:
-                       g_value_set_int (
+                       g_value_set_enum (
                                value, comp_editor_get_week_start_day (
                                COMP_EDITOR (object)));
                        return;
@@ -1909,13 +1909,12 @@ comp_editor_class_init (CompEditorClass *class)
        g_object_class_install_property (
                object_class,
                PROP_WEEK_START_DAY,
-               g_param_spec_int (
+               g_param_spec_enum (
                        "week-start-day",
                        "Week Start Day",
                        NULL,
-                       0,  /* Monday */
-                       6,  /* Sunday  */
-                       0,
+                       E_TYPE_DATE_WEEKDAY,
+                       G_DATE_MONDAY,
                        G_PARAM_READWRITE |
                        G_PARAM_STATIC_STRINGS));
 
@@ -2557,7 +2556,7 @@ comp_editor_set_use_24_hour_format (CompEditor *editor,
        g_object_notify (G_OBJECT (editor), "use-24-hour-format");
 }
 
-gint
+GDateWeekday
 comp_editor_get_week_start_day (CompEditor *editor)
 {
        g_return_val_if_fail (IS_COMP_EDITOR (editor), 0);
@@ -2567,10 +2566,10 @@ comp_editor_get_week_start_day (CompEditor *editor)
 
 void
 comp_editor_set_week_start_day (CompEditor *editor,
-                                gint week_start_day)
+                                GDateWeekday week_start_day)
 {
        g_return_if_fail (IS_COMP_EDITOR (editor));
-       g_return_if_fail (week_start_day >= 0 && week_start_day < 7);
+       g_return_if_fail (g_date_valid_weekday (week_start_day));
 
        if (week_start_day == editor->priv->week_start_day)
                return;
diff --git a/calendar/gui/dialogs/comp-editor.h b/calendar/gui/dialogs/comp-editor.h
index b343081..6721a87 100644
--- a/calendar/gui/dialogs/comp-editor.h
+++ b/calendar/gui/dialogs/comp-editor.h
@@ -134,9 +134,9 @@ gboolean    comp_editor_get_use_24_hour_format
 void           comp_editor_set_use_24_hour_format
                                                (CompEditor *editor,
                                                 gboolean use_24_hour_format);
-gint           comp_editor_get_week_start_day  (CompEditor *editor);
+GDateWeekday   comp_editor_get_week_start_day  (CompEditor *editor);
 void           comp_editor_set_week_start_day  (CompEditor *editor,
-                                                gint week_start_day);
+                                                GDateWeekday week_start_day);
 gint           comp_editor_get_work_day_end_hour
                                                (CompEditor *editor);
 void           comp_editor_set_work_day_end_hour
diff --git a/calendar/gui/dialogs/recurrence-page.c b/calendar/gui/dialogs/recurrence-page.c
index 3dd6d7c..3ceb084 100644
--- a/calendar/gui/dialogs/recurrence-page.c
+++ b/calendar/gui/dialogs/recurrence-page.c
@@ -748,8 +748,33 @@ simple_recur_to_comp (RecurrencePage *rpage,
        r.freq = e_dialog_combo_box_get (priv->interval_unit_combo, freq_map);
        r.interval = gtk_spin_button_get_value_as_int (
                GTK_SPIN_BUTTON (priv->interval_value));
-       r.week_start = ICAL_SUNDAY_WEEKDAY +
-               comp_editor_get_week_start_day (editor);
+
+       switch (comp_editor_get_week_start_day (editor)) {
+               case G_DATE_MONDAY:
+                       r.week_start = ICAL_MONDAY_WEEKDAY;
+                       break;
+               case G_DATE_TUESDAY:
+                       r.week_start = ICAL_TUESDAY_WEEKDAY;
+                       break;
+               case G_DATE_WEDNESDAY:
+                       r.week_start = ICAL_WEDNESDAY_WEEKDAY;
+                       break;
+               case G_DATE_THURSDAY:
+                       r.week_start = ICAL_THURSDAY_WEEKDAY;
+                       break;
+               case G_DATE_FRIDAY:
+                       r.week_start = ICAL_FRIDAY_WEEKDAY;
+                       break;
+               case G_DATE_SATURDAY:
+                       r.week_start = ICAL_SATURDAY_WEEKDAY;
+                       break;
+               case G_DATE_SUNDAY:
+                       r.week_start = ICAL_SUNDAY_WEEKDAY;
+                       break;
+               default:
+                       g_warn_if_reached ();
+                       break;
+       }
 
        /* Frequency-specific data */
 
@@ -759,36 +784,35 @@ simple_recur_to_comp (RecurrencePage *rpage,
                break;
 
        case ICAL_WEEKLY_RECURRENCE: {
-               guint8 day_mask;
+               EWeekdayChooser *chooser;
                gint i;
 
                g_return_if_fail (gtk_bin_get_child (GTK_BIN (priv->special)) != NULL);
                g_return_if_fail (E_IS_WEEKDAY_CHOOSER (priv->weekday_chooser));
 
-               day_mask = e_weekday_chooser_get_days (
-                       E_WEEKDAY_CHOOSER (priv->weekday_chooser));
+               chooser = E_WEEKDAY_CHOOSER (priv->weekday_chooser);
 
                i = 0;
 
-               if (day_mask & (1 << 0))
+               if (e_weekday_chooser_get_selected (chooser, E_DATE_SUNDAY))
                        r.by_day[i++] = ICAL_SUNDAY_WEEKDAY;
 
-               if (day_mask & (1 << 1))
+               if (e_weekday_chooser_get_selected (chooser, E_DATE_MONDAY))
                        r.by_day[i++] = ICAL_MONDAY_WEEKDAY;
 
-               if (day_mask & (1 << 2))
+               if (e_weekday_chooser_get_selected (chooser, E_DATE_TUESDAY))
                        r.by_day[i++] = ICAL_TUESDAY_WEEKDAY;
 
-               if (day_mask & (1 << 3))
+               if (e_weekday_chooser_get_selected (chooser, E_DATE_WEDNESDAY))
                        r.by_day[i++] = ICAL_WEDNESDAY_WEEKDAY;
 
-               if (day_mask & (1 << 4))
+               if (e_weekday_chooser_get_selected (chooser, E_DATE_THURSDAY))
                        r.by_day[i++] = ICAL_THURSDAY_WEEKDAY;
 
-               if (day_mask & (1 << 5))
+               if (e_weekday_chooser_get_selected (chooser, E_DATE_FRIDAY))
                        r.by_day[i++] = ICAL_FRIDAY_WEEKDAY;
 
-               if (day_mask & (1 << 6))
+               if (e_weekday_chooser_get_selected (chooser, E_DATE_SATURDAY))
                        r.by_day[i] = ICAL_SATURDAY_WEEKDAY;
 
                break;
@@ -1058,7 +1082,27 @@ make_weekly_special (RecurrencePage *rpage)
 
        /* Set the weekdays */
 
-       e_weekday_chooser_set_days (chooser, priv->weekday_day_mask);
+       e_weekday_chooser_set_selected (
+               chooser, G_DATE_SUNDAY,
+               (priv->weekday_day_mask & (1 << 0)) != 0);
+       e_weekday_chooser_set_selected (
+               chooser, G_DATE_MONDAY,
+               (priv->weekday_day_mask & (1 << 1)) != 0);
+       e_weekday_chooser_set_selected (
+               chooser, G_DATE_TUESDAY,
+               (priv->weekday_day_mask & (1 << 2)) != 0);
+       e_weekday_chooser_set_selected (
+               chooser, G_DATE_WEDNESDAY,
+               (priv->weekday_day_mask & (1 << 3)) != 0);
+       e_weekday_chooser_set_selected (
+               chooser, G_DATE_THURSDAY,
+               (priv->weekday_day_mask & (1 << 4)) != 0);
+       e_weekday_chooser_set_selected (
+               chooser, G_DATE_FRIDAY,
+               (priv->weekday_day_mask & (1 << 5)) != 0);
+       e_weekday_chooser_set_selected (
+               chooser, G_DATE_SATURDAY,
+               (priv->weekday_day_mask & (1 << 6)) != 0);
 
        g_signal_connect_swapped (
                chooser, "changed",
@@ -2086,12 +2130,56 @@ recurrence_page_set_dates (CompEditorPage *page,
                priv->weekday_blocked_day_mask = mask;
 
                if (priv->weekday_chooser != NULL) {
-                       e_weekday_chooser_set_days (
-                               E_WEEKDAY_CHOOSER (priv->weekday_chooser),
-                               priv->weekday_day_mask);
-                       e_weekday_chooser_set_blocked_days (
-                               E_WEEKDAY_CHOOSER (priv->weekday_chooser),
-                               priv->weekday_blocked_day_mask);
+                       EWeekdayChooser *chooser;
+                       guint8 mask;
+
+                       chooser = E_WEEKDAY_CHOOSER (priv->weekday_chooser);
+
+                       mask = priv->weekday_day_mask;
+                       e_weekday_chooser_set_selected (
+                               chooser, G_DATE_SUNDAY,
+                               (mask & (1 << 0)) != 0);
+                       e_weekday_chooser_set_selected (
+                               chooser, G_DATE_MONDAY,
+                               (mask & (1 << 1)) != 0);
+                       e_weekday_chooser_set_selected (
+                               chooser, G_DATE_TUESDAY,
+                               (mask & (1 << 2)) != 0);
+                       e_weekday_chooser_set_selected (
+                               chooser, G_DATE_WEDNESDAY,
+                               (mask & (1 << 3)) != 0);
+                       e_weekday_chooser_set_selected (
+                               chooser, G_DATE_THURSDAY,
+                               (mask & (1 << 4)) != 0);
+                       e_weekday_chooser_set_selected (
+                               chooser, G_DATE_FRIDAY,
+                               (mask & (1 << 5)) != 0);
+                       e_weekday_chooser_set_selected (
+                               chooser, G_DATE_SATURDAY,
+                               (mask & (1 << 6)) != 0);
+
+                       mask = priv->weekday_blocked_day_mask;
+                       e_weekday_chooser_set_blocked (
+                               chooser, G_DATE_SUNDAY,
+                               (mask & (1 << 0)) != 0);
+                       e_weekday_chooser_set_blocked (
+                               chooser, G_DATE_MONDAY,
+                               (mask & (1 << 1)) != 0);
+                       e_weekday_chooser_set_blocked (
+                               chooser, G_DATE_TUESDAY,
+                               (mask & (1 << 2)) != 0);
+                       e_weekday_chooser_set_blocked (
+                               chooser, G_DATE_WEDNESDAY,
+                               (mask & (1 << 3)) != 0);
+                       e_weekday_chooser_set_blocked (
+                               chooser, G_DATE_THURSDAY,
+                               (mask & (1 << 4)) != 0);
+                       e_weekday_chooser_set_blocked (
+                               chooser, G_DATE_FRIDAY,
+                               (mask & (1 << 5)) != 0);
+                       e_weekday_chooser_set_blocked (
+                               chooser, G_DATE_SATURDAY,
+                               (mask & (1 << 6)) != 0);
                }
        }
 
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c
index 1213ff1..a13e6fe 100644
--- a/calendar/gui/e-cal-model.c
+++ b/calendar/gui/e-cal-model.c
@@ -94,8 +94,8 @@ struct _ECalModelPrivate {
        /* Whether to compress weekends into one cell. */
        gboolean compress_weekend;
 
-       /* First day of the week: 0 (Monday) to 6 (Sunday) */
-       gint week_start_day;
+       /* First day of the week */
+       GDateWeekday week_start_day;
 
        /* Work days.  Indices are based on GDateWeekday.
         * The first element (G_DATE_BAD_WEEKDAY) is unused. */
@@ -273,7 +273,7 @@ cal_model_set_property (GObject *object,
                case PROP_WEEK_START_DAY:
                        e_cal_model_set_week_start_day (
                                E_CAL_MODEL (object),
-                               g_value_get_int (value));
+                               g_value_get_enum (value));
                        return;
 
                case PROP_WORK_DAY_MONDAY:
@@ -424,7 +424,7 @@ cal_model_get_property (GObject *object,
                        return;
 
                case PROP_WEEK_START_DAY:
-                       g_value_set_int (
+                       g_value_set_enum (
                                value,
                                e_cal_model_get_week_start_day (
                                E_CAL_MODEL (object)));
@@ -732,14 +732,14 @@ e_cal_model_class_init (ECalModelClass *class)
        g_object_class_install_property (
                object_class,
                PROP_WEEK_START_DAY,
-               g_param_spec_int (
+               g_param_spec_enum (
                        "week-start-day",
                        "Week Start Day",
                        NULL,
-                       0,  /* Monday */
-                       6,  /* Sunday */
-                       0,
-                       G_PARAM_READWRITE));
+                       E_TYPE_DATE_WEEKDAY,
+                       G_DATE_MONDAY,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT));
 
        g_object_class_install_property (
                object_class,
@@ -2186,21 +2186,20 @@ e_cal_model_set_use_default_reminder (ECalModel *model,
        g_object_notify (G_OBJECT (model), "use-default-reminder");
 }
 
-gint
+GDateWeekday
 e_cal_model_get_week_start_day (ECalModel *model)
 {
-       g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
+       g_return_val_if_fail (E_IS_CAL_MODEL (model), G_DATE_BAD_WEEKDAY);
 
        return model->priv->week_start_day;
 }
 
 void
 e_cal_model_set_week_start_day (ECalModel *model,
-                                gint week_start_day)
+                                GDateWeekday week_start_day)
 {
        g_return_if_fail (E_IS_CAL_MODEL (model));
-       g_return_if_fail (week_start_day >= 0);
-       g_return_if_fail (week_start_day < 7);
+       g_return_if_fail (g_date_valid_weekday (week_start_day));
 
        if (model->priv->week_start_day == week_start_day)
                return;
@@ -2281,7 +2280,7 @@ e_cal_model_get_work_day_first (ECalModel *model)
 
        g_return_val_if_fail (E_IS_CAL_MODEL (model), G_DATE_BAD_WEEKDAY);
 
-       weekday = e_cal_model_get_week_start_day (model) + 1;
+       weekday = e_cal_model_get_week_start_day (model);
 
        for (ii = 0; ii < 7; ii++) {
                if (e_cal_model_get_work_day (model, weekday))
@@ -2309,7 +2308,7 @@ e_cal_model_get_work_day_last (ECalModel *model)
 
        g_return_val_if_fail (E_IS_CAL_MODEL (model), G_DATE_BAD_WEEKDAY);
 
-       weekday = e_cal_model_get_week_start_day (model) + 1;
+       weekday = e_cal_model_get_week_start_day (model);
 
        for (ii = 0; ii < 7; ii++) {
                weekday = e_weekday_get_prev (weekday);
diff --git a/calendar/gui/e-cal-model.h b/calendar/gui/e-cal-model.h
index 610b227..f9eebad 100644
--- a/calendar/gui/e-cal-model.h
+++ b/calendar/gui/e-cal-model.h
@@ -220,9 +220,9 @@ gboolean    e_cal_model_get_use_default_reminder
 void           e_cal_model_set_use_default_reminder
                                                (ECalModel *model,
                                                 gboolean use_def_reminder);
-gint           e_cal_model_get_week_start_day  (ECalModel *model);
+GDateWeekday   e_cal_model_get_week_start_day  (ECalModel *model);
 void           e_cal_model_set_week_start_day  (ECalModel *model,
-                                                gint week_start_day);
+                                                GDateWeekday week_start_day);
 gboolean       e_cal_model_get_work_day        (ECalModel *model,
                                                 GDateWeekday weekday);
 void           e_cal_model_set_work_day        (ECalModel *model,
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index d96decd..4f0ca4e 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -3016,7 +3016,7 @@ e_day_view_find_work_week_start (EDayView *day_view,
        /* Calculate the first working day of the week. */
        first_work_day = e_cal_model_get_work_day_first (model);
        if (first_work_day == G_DATE_BAD_WEEKDAY)
-               first_work_day = e_cal_model_get_week_start_day (model) + 1;
+               first_work_day = e_cal_model_get_week_start_day (model);
 
        /* Calculate how many days we need to go back to the first workday. */
        if (weekday < first_work_day)
diff --git a/calendar/gui/e-week-view-layout.c b/calendar/gui/e-week-view-layout.c
index d725ec0..7c39e8c 100644
--- a/calendar/gui/e-week-view-layout.c
+++ b/calendar/gui/e-week-view-layout.c
@@ -44,7 +44,7 @@ static gint e_week_view_find_day      (time_t          time_to_find,
                                         time_t         *day_starts);
 static gint e_week_view_find_span_end  (gboolean        multi_week_view,
                                         gboolean        compress_weekend,
-                                        gint            display_start_day,
+                                        GDateWeekday    display_start_day,
                                         gint            day);
 
 GArray *
@@ -259,7 +259,7 @@ e_week_view_find_day (time_t time_to_find,
 static gint
 e_week_view_find_span_end (gboolean multi_week_view,
                            gboolean compress_weekend,
-                           gint display_start_day,
+                           GDateWeekday display_start_day,
                            gint day)
 {
        gint week, col, sat_col, end_col;
@@ -274,7 +274,8 @@ e_week_view_find_span_end (gboolean multi_week_view,
                /* If the weekend is compressed we must end any spans on
                 * Saturday and Sunday. */
                if (compress_weekend) {
-                       sat_col = (5 + 7 - display_start_day) % 7;
+                       sat_col = e_weekday_get_days_between (
+                               display_start_day, G_DATE_SATURDAY);
                        if (col <= sat_col)
                                end_col = sat_col;
                        else if (col == sat_col + 1)
@@ -291,13 +292,14 @@ void
 e_week_view_layout_get_day_position (gint day,
                                      gboolean multi_week_view,
                                      gint weeks_shown,
-                                     gint display_start_day,
+                                     GDateWeekday display_start_day,
                                      gboolean compress_weekend,
                                      gint *day_x,
                                      gint *day_y,
                                      gint *rows)
 {
-       gint week, day_of_week, col, weekend_col;
+       GDateWeekday day_of_week;
+       gint week, col, weekend_col;
 
        *day_x = *day_y = *rows = 0;
        g_return_if_fail (day >= 0);
@@ -307,12 +309,12 @@ e_week_view_layout_get_day_position (gint day,
 
                week = day / 7;
                col = day % 7;
-               day_of_week = (display_start_day + day) % 7;
-               if (compress_weekend && day_of_week >= 5) {
+               day_of_week = e_weekday_add_days (display_start_day, day);
+               if (compress_weekend && day_of_week >= G_DATE_SATURDAY) {
                        /* In the compressed view Saturday is above Sunday and
                         * both have just one row as opposed to 2 for all the
                         * other days. */
-                       if (day_of_week == 5) {
+                       if (day_of_week == G_DATE_SATURDAY) {
                                *day_y = week * 2;
                                *rows = 1;
                        } else {
@@ -326,9 +328,9 @@ e_week_view_layout_get_day_position (gint day,
                        /* If the weekend is compressed and the day is after
                         * the weekend we have to move back a column. */
                        if (compress_weekend) {
-                               /* Calculate where the weekend column is.
-                                * Note that 5 is Saturday. */
-                               weekend_col = (5 + 7 - display_start_day) % 7;
+                               /* Calculate where the weekend column is. */
+                               weekend_col = e_weekday_get_days_between (
+                                       display_start_day, G_DATE_SATURDAY);
                                if (col > weekend_col)
                                        col--;
                        }
@@ -445,18 +447,20 @@ e_week_view_layout_get_span_position (EWeekViewEvent *event,
                                       EWeekViewEventSpan *span,
                                       gint rows_per_cell,
                                       gint rows_per_compressed_cell,
-                                      gint display_start_day,
+                                      GDateWeekday display_start_day,
                                       gboolean multi_week_view,
                                       gboolean compress_weekend,
                                       gint *span_num_days)
 {
-       gint end_day_of_week;
+       GDateWeekday end_day_of_week;
+       guint n_days;
 
        if (multi_week_view && span->row >= rows_per_cell)
                return FALSE;
 
-       end_day_of_week = (display_start_day + span->start_day
-                          + span->num_days - 1) % 7;
+       n_days = span->start_day + span->num_days - 1;
+       end_day_of_week = e_weekday_add_days (display_start_day, n_days);
+
        *span_num_days = span->num_days;
        /* Check if the row will not be visible in compressed cells. */
        if (span->row >= rows_per_compressed_cell) {
@@ -466,13 +470,13 @@ e_week_view_layout_get_span_position (EWeekViewEvent *event,
                                 * we skip it, else we shorten it. If it ends
                                 * on a Sunday it must be 1 day long and we
                                 * skip it. */
-                               if (end_day_of_week == 5) {        /* Sat */
+                               if (end_day_of_week == G_DATE_SATURDAY) {
                                        if (*span_num_days == 1) {
                                                return FALSE;
                                        } else {
                                                (*span_num_days)--;
                                        }
-                               } else if (end_day_of_week == 6) { /* Sun */
+                               } else if (end_day_of_week == G_DATE_SUNDAY) {
                                        return FALSE;
                                }
                        }
diff --git a/calendar/gui/e-week-view-layout.h b/calendar/gui/e-week-view-layout.h
index 5f1e287..a4a8777 100644
--- a/calendar/gui/e-week-view-layout.h
+++ b/calendar/gui/e-week-view-layout.h
@@ -31,35 +31,37 @@ G_BEGIN_DECLS
 /* I've split these functions away from EWeekView so we can use them for
  * printing. */
 
-GArray * e_week_view_layout_events     (GArray         *events,
-                                        GArray         *old_spans,
-                                        gboolean        multi_week_view,
-                                        gint            weeks_shown,
-                                        gboolean        compress_weekend,
-                                        gint            start_weekday,
-                                        time_t         *day_starts,
-                                        gint           *rows_per_day);
+GArray *       e_week_view_layout_events       (GArray *events,
+                                                GArray *old_spans,
+                                                gboolean multi_week_view,
+                                                gint weeks_shown,
+                                                gboolean compress_weekend,
+                                                gint start_weekday,
+                                                time_t *day_starts,
+                                                gint *rows_per_day);
 
 /* Returns which 'cell' in the table the day appears in. Note that most days
  * have a height of 2 rows, but Sat/Sun are sometimes compressed so they have
  * a height of only 1 row. */
-void e_week_view_layout_get_day_position (gint          day,
-                                        gboolean        multi_week_view,
-                                        gint            weeks_shown,
-                                        gint            display_start_day,
-                                        gboolean        compress_weekend,
-                                        gint           *cell_x,
-                                        gint           *cell_y,
-                                        gint           *rows);
+void           e_week_view_layout_get_day_position
+                                               (gint day,
+                                                gboolean multi_week_view,
+                                                gint weeks_shown,
+                                                GDateWeekday display_start_day,
+                                                gboolean compress_weekend,
+                                                gint *cell_x,
+                                                gint *cell_y,
+                                                gint *rows);
 
-gboolean e_week_view_layout_get_span_position (EWeekViewEvent *event,
-                                              EWeekViewEventSpan *span,
-                                              gint      rows_per_cell,
-                                              gint      rows_per_compressed_cell,
-                                              gint      display_start_day,
-                                              gboolean  multi_week_view,
-                                              gboolean  compress_weekend,
-                                              gint     *span_num_days);
+gboolean       e_week_view_layout_get_span_position
+                                               (EWeekViewEvent *event,
+                                                EWeekViewEventSpan *span,
+                                                gint rows_per_cell,
+                                                gint rows_per_compressed_cell,
+                                                GDateWeekday display_start_day,
+                                                gboolean multi_week_view,
+                                                gboolean compress_weekend,
+                                                gint *span_num_days);
 
 G_END_DECLS
 
diff --git a/calendar/gui/e-week-view-titles-item.c b/calendar/gui/e-week-view-titles-item.c
index 3081c5e..49bbe48 100644
--- a/calendar/gui/e-week-view-titles-item.c
+++ b/calendar/gui/e-week-view-titles-item.c
@@ -133,7 +133,7 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
        GtkAllocation allocation;
        gboolean abbreviated;
        gboolean compress_weekend;
-       gint weekday;
+       GDateWeekday weekday;
        PangoLayout *layout;
 
        titles_item = E_WEEK_VIEW_TITLES_ITEM (canvas_item);
@@ -173,9 +173,9 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
 
        /* Draw the date. Set a clipping rectangle so we don't draw over the
         * next day. */
-       weekday = week_view->display_start_day;
+       weekday = e_week_view_get_display_start_day (week_view);
        for (col = 0; col < week_view->columns; col++) {
-               if (weekday == 5 && compress_weekend)
+               if (weekday == G_DATE_SATURDAY && compress_weekend)
                        g_snprintf (
                                buffer, sizeof (buffer), "%s/%s",
                                e_get_weekday_name (G_DATE_SATURDAY, TRUE),
@@ -183,7 +183,7 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
                else
                        g_snprintf (
                                buffer, sizeof (buffer), "%s",
-                               e_get_weekday_name (weekday + 1, abbreviated));
+                               e_get_weekday_name (weekday, abbreviated));
 
                cairo_save (cr);
 
@@ -193,7 +193,7 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
                        week_view->col_widths[col], allocation.height - 2);
                cairo_clip (cr);
 
-               if (weekday == 5 && compress_weekend)
+               if (weekday == G_DATE_SATURDAY && compress_weekend)
                        date_width = week_view->abbr_day_widths[5]
                                + week_view->slash_width
                                + week_view->abbr_day_widths[6];
@@ -234,12 +234,9 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
                        cairo_fill (cr);
                }
 
-               if (weekday == 5 && compress_weekend)
-                       weekday += 2;
-               else
-                       weekday++;
-
-               weekday = weekday % 7;
+               weekday = e_weekday_get_next (weekday);
+               if (weekday == G_DATE_SUNDAY && compress_weekend)
+                       weekday = e_weekday_get_next (weekday);
        }
 
        g_object_unref (layout);
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index c80d9f3..7af4d85 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -98,6 +98,11 @@ struct _EWeekViewPrivate {
 
        /* Whether to update the base date when the time range changes. */
        gboolean update_base_date;
+
+       /* The first day of the week we display.  This will usually be
+        * week_start_day, but if the Sat & Sun are compressed and the
+        * week starts on Sunday then we have to use Saturday. */
+       GDateWeekday display_start_day;
 };
 
 typedef struct {
@@ -373,7 +378,9 @@ week_view_time_range_changed_cb (EWeekView *week_view,
                                  ECalModel *model)
 {
        GDate date, base_date;
-       gint day_offset, weekday, week_start_offset;
+       GDateWeekday weekday;
+       GDateWeekday display_start_day;
+       guint day_offset, week_start_offset;
        gint num_days;
        gboolean update_adjustment_value = FALSE;
 
@@ -381,11 +388,12 @@ week_view_time_range_changed_cb (EWeekView *week_view,
 
        time_to_gdate_with_zone (&date, start_time, e_calendar_view_get_timezone (E_CALENDAR_VIEW 
(week_view)));
 
-       /* Calculate the weekday of the given date, 0 = Mon. */
-       weekday = g_date_get_weekday (&date) - 1;
+       weekday = g_date_get_weekday (&date);
+       display_start_day = e_week_view_get_display_start_day (week_view);
 
        /* Convert it to an offset from the start of the display. */
-       week_start_offset = (weekday + 7 - week_view->display_start_day) % 7;
+       week_start_offset = e_weekday_get_days_between (
+               display_start_day, weekday);
 
        /* Set the day_offset to the result, so we move back to the
         * start of the week. */
@@ -408,7 +416,7 @@ week_view_time_range_changed_cb (EWeekView *week_view,
            || g_date_compare (&week_view->priv->first_day_shown, &base_date)) {
                week_view->priv->first_day_shown = base_date;
                start_time = time_add_day_with_zone (
-                       start_time, -day_offset,
+                       start_time, -((gint) day_offset),
                        e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
                start_time = time_day_begin_with_zone (
                        start_time,
@@ -1477,6 +1485,7 @@ e_week_view_init (EWeekView *week_view)
        week_view->priv->compress_weekend = TRUE;
        week_view->priv->show_event_end_times = TRUE;
        week_view->priv->update_base_date = TRUE;
+       week_view->priv->display_start_day = G_DATE_MONDAY;
 
        gtk_widget_set_can_focus (GTK_WIDGET (week_view), TRUE);
 
@@ -1496,7 +1505,6 @@ e_week_view_init (EWeekView *week_view)
        week_view->scroll_by_week_notif_id = 0;
        week_view->rows = 6;
        week_view->columns = 2;
-       week_view->display_start_day = 0;       /* Monday. */
 
        g_date_clear (&week_view->base_date, 1);
        g_date_clear (&week_view->priv->first_day_shown, 1);
@@ -1985,7 +1993,10 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
                                  GDate *date)
 {
        GDate base_date;
-       gint weekday, day_offset, num_days;
+       GDateWeekday weekday;
+       GDateWeekday display_start_day;
+       guint day_offset;
+       gint num_days;
        gboolean update_adjustment_value = FALSE;
        guint32 old_selection_start_julian = 0, old_selection_end_julian = 0;
        struct icaltimetype start_tt = icaltime_null_time ();
@@ -2003,11 +2014,11 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
                        + week_view->selection_end_day;
        }
 
-       /* Calculate the weekday of the given date, 0 = Mon. */
-       weekday = g_date_get_weekday (date) - 1;
+       weekday = g_date_get_weekday (date);
+       display_start_day = e_week_view_get_display_start_day (week_view);
 
        /* Convert it to an offset from the start of the display. */
-       day_offset = (weekday + 7 - week_view->display_start_day) % 7;
+       day_offset = e_weekday_get_days_between (display_start_day, weekday);
 
        /* Calculate the base date, i.e. the first day shown when the
         * scrollbar adjustment value is 0. */
@@ -2072,6 +2083,14 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
        gtk_widget_queue_draw (week_view->main_canvas);
 }
 
+GDateWeekday
+e_week_view_get_display_start_day (EWeekView *week_view)
+{
+       g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), G_DATE_BAD_WEEKDAY);
+
+       return week_view->priv->display_start_day;
+}
+
 /* Recalculates the time_t corresponding to the start of each day. */
 static void
 e_week_view_recalc_day_starts (EWeekView *week_view,
@@ -2307,8 +2326,9 @@ static gboolean
 e_week_view_recalc_display_start_day (EWeekView *week_view)
 {
        ECalModel *model;
-       gint week_start_day;
-       gint display_start_day;
+       GDateWeekday week_start_day;
+       GDateWeekday display_start_day;
+       gboolean changed;
 
        model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view));
        week_start_day = e_cal_model_get_week_start_day (model);
@@ -2318,20 +2338,19 @@ e_week_view_recalc_display_start_day (EWeekView *week_view)
         * is Sunday. */
        display_start_day = week_start_day;
 
-       if (display_start_day == 6) {
+       if (display_start_day == G_DATE_SUNDAY) {
                if (!e_week_view_get_multi_week_view (week_view))
-                       display_start_day = 5;
+                       display_start_day = G_DATE_SATURDAY;
 
                if (e_week_view_get_compress_weekend (week_view))
-                       display_start_day = 5;
+                       display_start_day = G_DATE_SATURDAY;
        }
 
-       if (week_view->display_start_day != display_start_day) {
-               week_view->display_start_day = display_start_day;
-               return TRUE;
-       }
+       changed = (display_start_day != week_view->priv->display_start_day);
 
-       return FALSE;
+       week_view->priv->display_start_day = display_start_day;
+
+       return changed;
 }
 
 /* Checks if the users participation status is NEEDS-ACTION and shows the summary as bold text */
@@ -2492,7 +2511,7 @@ e_week_view_get_day_position (EWeekView *week_view,
                day,
                e_week_view_get_multi_week_view (week_view),
                e_week_view_get_weeks_shown (week_view),
-               week_view->display_start_day,
+               e_week_view_get_display_start_day (week_view),
                e_week_view_get_compress_weekend (week_view),
                &cell_x, &cell_y, &cell_h);
 
@@ -2548,7 +2567,7 @@ e_week_view_get_span_position (EWeekView *week_view,
                event, span,
                week_view->rows_per_cell,
                week_view->rows_per_compressed_cell,
-               week_view->display_start_day,
+               e_week_view_get_display_start_day (week_view),
                e_week_view_get_multi_week_view (week_view),
                e_week_view_get_compress_weekend (week_view),
                &num_days)) {
@@ -2817,9 +2836,12 @@ e_week_view_convert_position_to_day (EWeekView *week_view,
                                      gint x,
                                      gint y)
 {
+       GDateWeekday display_start_day;
        gint col, row, grid_x = -1, grid_y = -1, week, day;
        gint weekend_col;
 
+       display_start_day = e_week_view_get_display_start_day (week_view);
+
        /* First we convert it to a grid position. */
        for (col = 0; col <= week_view->columns; col++) {
                if (x < week_view->col_offsets[col]) {
@@ -2845,7 +2867,8 @@ e_week_view_convert_position_to_day (EWeekView *week_view,
                day = grid_x;
 
                if (e_week_view_get_compress_weekend (week_view)) {
-                       weekend_col = (5 + 7 - week_view->display_start_day) % 7;
+                       weekend_col = e_weekday_get_days_between (
+                               display_start_day, G_DATE_SATURDAY);
                        if (grid_x > weekend_col
                            || (grid_x == weekend_col && grid_y % 2 == 1))
                                day++;
@@ -2857,7 +2880,7 @@ e_week_view_convert_position_to_day (EWeekView *week_view,
                        gint day_x = 0, day_y = 0, rows = 0;
                        e_week_view_layout_get_day_position (
                                day, FALSE, 1,
-                               week_view->display_start_day,
+                               e_week_view_get_display_start_day (week_view),
                                e_week_view_get_compress_weekend (week_view),
                                &day_x, &day_y, &rows);
 
@@ -3051,7 +3074,7 @@ e_week_view_check_layout (EWeekView *week_view)
                        e_week_view_get_multi_week_view (week_view),
                        e_week_view_get_weeks_shown (week_view),
                        e_week_view_get_compress_weekend (week_view),
-                       week_view->display_start_day,
+                       e_week_view_get_display_start_day (week_view),
                        week_view->day_starts,
                        week_view->rows_per_day);
 
@@ -3101,6 +3124,7 @@ static void
 e_week_view_reshape_events (EWeekView *week_view)
 {
        EWeekViewEvent *event;
+       GDateWeekday display_start_day;
        gint event_num, span_num;
        gint num_days, day, day_x, day_y, day_w, day_h, max_rows;
        gboolean is_weekend;
@@ -3138,9 +3162,18 @@ e_week_view_reshape_events (EWeekView *week_view)
 
        /* Reshape the jump buttons and show/hide them as appropriate. */
        num_days = e_week_view_get_weeks_shown (week_view) * 7;
+       display_start_day = e_week_view_get_display_start_day (week_view);
        for (day = 0; day < num_days; day++) {
+               switch (e_weekday_add_days (display_start_day, day)) {
+                       case G_DATE_SATURDAY:
+                       case G_DATE_SUNDAY:
+                               is_weekend = TRUE;
+                               break;
+                       default:
+                               is_weekend = FALSE;
+                               break;
+               }
 
-               is_weekend = ((week_view->display_start_day + day) % 7 >= 5) ? TRUE : FALSE;
                if (!is_weekend || (
                    e_week_view_get_multi_week_view (week_view)
                    && !e_week_view_get_compress_weekend (week_view)))
diff --git a/calendar/gui/e-week-view.h b/calendar/gui/e-week-view.h
index ae528b3..00181d1 100644
--- a/calendar/gui/e-week-view.h
+++ b/calendar/gui/e-week-view.h
@@ -208,11 +208,6 @@ struct _EWeekView {
        gboolean month_scroll_by_week;
        guint scroll_by_week_notif_id;
 
-       /* The first day of the week we display, 0 (Monday) to 6 (Sunday).
-        * This will usually be week_start_day, but if the weekend is
-        * compressed, and week_start_day is Sunday we have to use Saturday. */
-       gint display_start_day;
-
        /* The vertical offset of the events from the top of the cells. */
        gint events_y_offset;
 
@@ -348,6 +343,10 @@ void               e_week_view_get_first_day_shown (EWeekView *week_view,
 void           e_week_view_set_first_day_shown (EWeekView *week_view,
                                                 GDate *date);
 
+/* The first day of the week we display. */
+GDateWeekday   e_week_view_get_display_start_day
+                                               (EWeekView *week_view);
+
 /* The selected time range. The EWeekView will show the corresponding
  * month and the days between start_time and end_time will be selected.
  * To select a single day, use the same value for start_time & end_time. */
diff --git a/calendar/gui/e-weekday-chooser.c b/calendar/gui/e-weekday-chooser.c
index 4585699..ef459e5 100644
--- a/calendar/gui/e-weekday-chooser.c
+++ b/calendar/gui/e-weekday-chooser.c
@@ -36,17 +36,14 @@
 
 /* Private part of the EWeekdayChooser structure */
 struct _EWeekdayChooserPrivate {
-       /* Selected days; see weekday_chooser_set_days() */
-       guint8 day_mask;
+       gboolean blocked_weekdays[8];   /* indexed by GDateWeekday */
+       gboolean selected_weekdays[8];  /* indexed by GDateWeekday */
 
-       /* Blocked days; these cannot be modified */
-       guint8 blocked_day_mask;
-
-       /* Day that defines the start of the week; 0 = Sunday, ..., 6 = Saturday */
-       gint week_start_day;
+       /* Day that defines the start of the week. */
+       GDateWeekday week_start_day;
 
        /* Current keyboard focus day */
-       gint focus_day;
+       GDateWeekday focus_day;
 
        /* Metrics */
        gint font_ascent, font_descent;
@@ -76,29 +73,16 @@ G_DEFINE_TYPE_WITH_CODE (
        G_IMPLEMENT_INTERFACE (
                E_TYPE_EXTENSIBLE, NULL))
 
-static gchar *
-get_day_text (gint day_index)
-{
-       GDateWeekday weekday;
-
-       /* Convert from tm_wday to GDateWeekday. */
-       weekday = (day_index == 0) ? G_DATE_SUNDAY : day_index;
-
-       return g_strdup (e_get_weekday_name (weekday, TRUE));
-}
-
 static void
 colorize_items (EWeekdayChooser *chooser)
 {
-       EWeekdayChooserPrivate *priv;
        GdkColor *outline, *focus_outline;
        GdkColor *fill, *sel_fill;
        GdkColor *text_fill, *sel_text_fill;
        GtkStateType state;
        GtkStyle *style;
-       gint i;
-
-       priv = chooser->priv;
+       GDateWeekday weekday;
+       gint ii;
 
        state = gtk_widget_get_state (GTK_WIDGET (chooser));
        style = gtk_widget_get_style (GTK_WIDGET (chooser));
@@ -112,15 +96,12 @@ colorize_items (EWeekdayChooser *chooser)
        sel_fill = &style->bg[GTK_STATE_SELECTED];
        sel_text_fill = &style->fg[GTK_STATE_SELECTED];
 
-       for (i = 0; i < 7; i++) {
-               gint day;
-               GdkColor *f, *t, *o;
+       weekday = e_weekday_chooser_get_week_start_day (chooser);
 
-               day = i + priv->week_start_day;
-               if (day >= 7)
-                       day -= 7;
+       for (ii = 0; ii < 7; ii++) {
+               GdkColor *f, *t, *o;
 
-               if (priv->day_mask & (0x1 << day)) {
+               if (chooser->priv->selected_weekdays[weekday]) {
                        f = sel_fill;
                        t = sel_text_fill;
                } else {
@@ -128,34 +109,34 @@ colorize_items (EWeekdayChooser *chooser)
                        t = text_fill;
                }
 
-               if (day == priv->focus_day)
+               if (weekday == chooser->priv->focus_day)
                        o = focus_outline;
                else
                        o = outline;
 
                gnome_canvas_item_set (
-                       priv->boxes[i],
+                       chooser->priv->boxes[ii],
                        "fill_color_gdk", f,
                        "outline_color_gdk", o,
                        NULL);
 
                gnome_canvas_item_set (
-                       priv->labels[i],
+                       chooser->priv->labels[ii],
                        "fill_color_gdk", t,
                        NULL);
+
+               weekday = e_weekday_get_next (weekday);
        }
 }
 
 static void
 configure_items (EWeekdayChooser *chooser)
 {
-       EWeekdayChooserPrivate *priv;
        GtkAllocation allocation;
        gint width, height;
        gint box_width;
-       gint i;
-
-       priv = chooser->priv;
+       GDateWeekday weekday;
+       gint ii;
 
        gtk_widget_get_allocation (GTK_WIDGET (chooser), &allocation);
 
@@ -164,31 +145,26 @@ configure_items (EWeekdayChooser *chooser)
 
        box_width = (width - 1) / 7;
 
-       for (i = 0; i < 7; i++) {
-               gchar *c;
-               gint day;
-
-               day = i + priv->week_start_day;
-               if (day >= 7)
-                       day -= 7;
+       weekday = e_weekday_chooser_get_week_start_day (chooser);
 
+       for (ii = 0; ii < 7; ii++) {
                gnome_canvas_item_set (
-                       priv->boxes[i],
-                       "x1", (gdouble) (i * box_width),
+                       chooser->priv->boxes[ii],
+                       "x1", (gdouble) (ii * box_width),
                        "y1", (gdouble) 0,
-                       "x2", (gdouble) ((i + 1) * box_width),
+                       "x2", (gdouble) ((ii + 1) * box_width),
                        "y2", (gdouble) (height - 1),
                        "line_width", 0.0,
                        NULL);
 
-               c = get_day_text (day);
                gnome_canvas_item_set (
-                       priv->labels[i],
-                       "text", c,
-                       "x", (gdouble) (i * box_width) + PADDING,
+                       chooser->priv->labels[ii],
+                       "text", e_get_weekday_name (weekday, TRUE),
+                       "x", (gdouble) (ii * box_width) + PADDING,
                        "y", (gdouble) (1 + PADDING),
                        NULL);
-               g_free (c);
+
+               weekday = e_weekday_get_next (weekday);
        }
 
        colorize_items (chooser);
@@ -204,7 +180,7 @@ weekday_chooser_set_property (GObject *object,
                case PROP_WEEK_START_DAY:
                        e_weekday_chooser_set_week_start_day (
                                E_WEEKDAY_CHOOSER (object),
-                               g_value_get_int (value));
+                               g_value_get_enum (value));
                        return;
        }
 
@@ -219,7 +195,7 @@ weekday_chooser_get_property (GObject *object,
 {
        switch (property_id) {
                case PROP_WEEK_START_DAY:
-                       g_value_set_int (
+                       g_value_set_enum (
                                value,
                                e_weekday_chooser_get_week_start_day (
                                E_WEEKDAY_CHOOSER (object)));
@@ -279,11 +255,11 @@ weekday_chooser_style_set (GtkWidget *widget,
        EWeekdayChooser *chooser;
        EWeekdayChooserPrivate *priv;
        gint max_width;
-       gint i;
        PangoFontDescription *font_desc;
        PangoContext *pango_context;
        PangoFontMetrics *font_metrics;
        PangoLayout *layout;
+       GDateWeekday weekday;
 
        chooser = E_WEEKDAY_CHOOSER (widget);
        priv = chooser->priv;
@@ -303,14 +279,13 @@ weekday_chooser_style_set (GtkWidget *widget,
 
        max_width = 0;
 
-       for (i = 0; i < 7; i++) {
-               gchar *c;
+       for (weekday = G_DATE_MONDAY; weekday <= G_DATE_SUNDAY; weekday++) {
+               const gchar *name;
                gint w;
 
-               c = get_day_text (i);
-               pango_layout_set_text (layout, c, strlen (c));
+               name = e_get_weekday_name (weekday, TRUE);
+               pango_layout_set_text (layout, name, strlen (name));
                pango_layout_get_pixel_size (layout, &w, NULL);
-               g_free (c);
 
                if (w > max_width)
                        max_width = w;
@@ -362,23 +337,21 @@ weekday_chooser_focus (GtkWidget *widget,
                        GtkDirectionType direction)
 {
        EWeekdayChooser *chooser;
-       EWeekdayChooserPrivate *priv;
 
-       g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (widget), FALSE);
        chooser = E_WEEKDAY_CHOOSER (widget);
-       priv = chooser->priv;
 
        if (!gtk_widget_get_can_focus (widget))
                return FALSE;
 
        if (gtk_widget_has_focus (widget)) {
-               priv->focus_day = -1;
+               chooser->priv->focus_day = G_DATE_BAD_WEEKDAY;
                colorize_items (chooser);
                return FALSE;
        }
 
-       priv->focus_day = priv->week_start_day;
-       gnome_canvas_item_grab_focus (priv->boxes[priv->focus_day]);
+       chooser->priv->focus_day = chooser->priv->week_start_day;
+       gnome_canvas_item_grab_focus (chooser->priv->boxes[0]);
+
        colorize_items (chooser);
 
        return TRUE;
@@ -408,13 +381,12 @@ e_weekday_chooser_class_init (EWeekdayChooserClass *class)
        g_object_class_install_property (
                object_class,
                PROP_WEEK_START_DAY,
-               g_param_spec_int (
+               g_param_spec_enum (
                        "week-start-day",
                        "Week Start Day",
                        NULL,
-                       0,  /* Monday */
-                       6,  /* Sunday */
-                       0,
+                       E_TYPE_DATE_WEEKDAY,
+                       G_DATE_MONDAY,
                        G_PARAM_READWRITE |
                        G_PARAM_STATIC_STRINGS));
 
@@ -430,20 +402,15 @@ e_weekday_chooser_class_init (EWeekdayChooserClass *class)
 
 static void
 day_clicked (EWeekdayChooser *chooser,
-             gint index)
+             GDateWeekday weekday)
 {
-       EWeekdayChooserPrivate *priv = chooser->priv;
-       guint8 day_mask;
+       gboolean selected;
 
-       if (priv->blocked_day_mask & (0x1 << index))
+       if (chooser->priv->blocked_weekdays[weekday])
                return;
 
-       if (priv->day_mask & (0x1 << index))
-               day_mask = priv->day_mask & ~(0x1 << index);
-       else
-               day_mask = priv->day_mask | (0x1 << index);
-
-       e_weekday_chooser_set_days (chooser, day_mask);
+       selected = e_weekday_chooser_get_selected (chooser, weekday);
+       e_weekday_chooser_set_selected (chooser, weekday, !selected);
 }
 
 static gint
@@ -452,18 +419,21 @@ handle_key_press_event (EWeekdayChooser *chooser,
 {
        EWeekdayChooserPrivate *priv = chooser->priv;
        guint keyval = event->key.keyval;
+       guint index;
 
-       if (priv->focus_day == -1)
-               priv->focus_day = priv->week_start_day;
+       if (chooser->priv->focus_day == G_DATE_BAD_WEEKDAY)
+               chooser->priv->focus_day = chooser->priv->week_start_day;
 
        switch (keyval) {
                case GDK_KEY_Up:
                case GDK_KEY_Right:
-                       priv->focus_day += 1;
+                       chooser->priv->focus_day =
+                               e_weekday_get_next (chooser->priv->focus_day);
                        break;
                case GDK_KEY_Down:
                case GDK_KEY_Left:
-                       priv->focus_day -= 1;
+                       chooser->priv->focus_day =
+                               e_weekday_get_prev (chooser->priv->focus_day);
                        break;
                case GDK_KEY_space:
                case GDK_KEY_Return:
@@ -473,28 +443,27 @@ handle_key_press_event (EWeekdayChooser *chooser,
                        return FALSE;
        }
 
-       if (priv->focus_day > 6)
-               priv->focus_day = 0;
-       if (priv->focus_day < 0)
-               priv->focus_day = 6;
-
        colorize_items (chooser);
-       gnome_canvas_item_grab_focus (priv->boxes[priv->focus_day]);
+
+       index = e_weekday_get_days_between (
+               chooser->priv->week_start_day,
+               chooser->priv->focus_day);
+
+       gnome_canvas_item_grab_focus (chooser->priv->boxes[index]);
+
        return TRUE;
 }
 
 /* Event handler for the day items */
-static gint
+static gboolean
 day_event_cb (GnomeCanvasItem *item,
               GdkEvent *event,
               gpointer data)
 {
        EWeekdayChooser *chooser;
-       EWeekdayChooserPrivate *priv;
-       gint i;
+       gint ii;
 
        chooser = E_WEEKDAY_CHOOSER (data);
-       priv = chooser->priv;
 
        if (event->type == GDK_KEY_PRESS)
                return handle_key_press_event (chooser, event);
@@ -504,19 +473,22 @@ day_event_cb (GnomeCanvasItem *item,
 
        /* Find which box was clicked */
 
-       for (i = 0; i < 7; i++)
-               if (priv->boxes[i] == item || priv->labels[i] == item)
+       for (ii = 0; ii < 7; ii++) {
+               if (chooser->priv->boxes[ii] == item)
+                       break;
+               if (chooser->priv->labels[ii] == item)
                        break;
+       }
+
+       g_return_val_if_fail (ii < 7, FALSE);
 
-       g_return_val_if_fail (i != 7, TRUE);
+       chooser->priv->focus_day = e_weekday_add_days (
+               chooser->priv->week_start_day, ii);
 
-       i += priv->week_start_day;
-       if (i >= 7)
-               i -= 7;
+       gnome_canvas_item_grab_focus (chooser->priv->boxes[ii]);
+
+       day_clicked (chooser, chooser->priv->focus_day);
 
-       priv->focus_day = i;
-       gnome_canvas_item_grab_focus (priv->boxes[i]);
-       day_clicked (chooser, i);
        return TRUE;
 }
 
@@ -525,29 +497,26 @@ day_event_cb (GnomeCanvasItem *item,
 static void
 create_items (EWeekdayChooser *chooser)
 {
-       EWeekdayChooserPrivate *priv;
        GnomeCanvasGroup *parent;
-       gint i;
-
-       priv = chooser->priv;
+       gint ii;
 
        parent = gnome_canvas_root (GNOME_CANVAS (chooser));
 
-       for (i = 0; i < 7; i++) {
-               priv->boxes[i] = gnome_canvas_item_new (
+       for (ii = 0; ii < 7; ii++) {
+               chooser->priv->boxes[ii] = gnome_canvas_item_new (
                        parent,
                        GNOME_TYPE_CANVAS_RECT,
                        NULL);
                g_signal_connect (
-                       priv->boxes[i], "event",
+                       chooser->priv->boxes[ii], "event",
                        G_CALLBACK (day_event_cb), chooser);
 
-               priv->labels[i] = gnome_canvas_item_new (
+               chooser->priv->labels[ii] = gnome_canvas_item_new (
                        parent,
                        GNOME_TYPE_CANVAS_TEXT,
                        NULL);
                g_signal_connect (
-                       priv->labels[i], "event",
+                       chooser->priv->labels[ii], "event",
                        G_CALLBACK (day_event_cb), chooser);
        }
 }
@@ -577,74 +546,81 @@ e_weekday_chooser_new (void)
 /**
  * e_weekday_chooser_get_days:
  * @chooser: an #EWeekdayChooser
+ * @weekday: a #GDateWeekday
  *
- * Queries the days that are selected in @chooser.
+ * Returns whether @weekday is selected.
  *
- * Return value: Bit mask of selected days.  Sunday is bit 0, Monday is bit 1,
- * etc.
+ * Returns: whether @weekday is selected
  **/
-guint8
-e_weekday_chooser_get_days (EWeekdayChooser *chooser)
+gboolean
+e_weekday_chooser_get_selected (EWeekdayChooser *chooser,
+                                GDateWeekday weekday)
 {
-       g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), 0);
+       g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), FALSE);
+       g_return_val_if_fail (g_date_valid_weekday (weekday), FALSE);
 
-       return chooser->priv->day_mask;
+       return chooser->priv->selected_weekdays[weekday];
 }
 
 /**
- * e_weekday_chooser_set_days:
+ * e_weekday_chooser_set_selected:
  * @chooser: an #EWeekdayChooser
- * @day_mask: Bitmask with the days to be selected.
+ * @weekday: a #GDateWeekday
+ * @selected: selected flag
  *
- * Sets the days that are selected in @chooser.  In the @day_mask,
- * Sunday is bit 0, Monday is bit 1, etc.
+ * Selects or deselects @weekday.
  **/
 void
-e_weekday_chooser_set_days (EWeekdayChooser *chooser,
-                            guint8 day_mask)
+e_weekday_chooser_set_selected (EWeekdayChooser *chooser,
+                                GDateWeekday weekday,
+                                gboolean selected)
 {
        g_return_if_fail (E_IS_WEEKDAY_CHOOSER (chooser));
+       g_return_if_fail (g_date_valid_weekday (weekday));
+
+       chooser->priv->selected_weekdays[weekday] = selected;
 
-       chooser->priv->day_mask = day_mask;
        colorize_items (chooser);
 
        g_signal_emit (chooser, chooser_signals[CHANGED], 0);
 }
 
 /**
- * e_weekday_chooser_get_blocked_days:
+ * e_weekday_chooser_get_blocked:
  * @chooser: an #EWeekdayChooser
+ * @weekday: a #GDateWeekday
  *
- * Queries the set of days that the @chooser prevents from being modified
- * by the user.
+ * Returns whether @weekday is blocked from being modified by the user.
  *
- * Return value: Bit mask of blocked days, with the same format as that
- * returned by e_weekday_chooser_get_days().
+ * Returns: whether @weekday is blocked
  **/
-guint
-e_weekday_chooser_get_blocked_days (EWeekdayChooser *chooser)
+gboolean
+e_weekday_chooser_get_blocked (EWeekdayChooser *chooser,
+                               GDateWeekday weekday)
 {
-       g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), 0);
+       g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), FALSE);
+       g_return_val_if_fail (g_date_valid_weekday (weekday), FALSE);
 
-       return chooser->priv->blocked_day_mask;
+       return chooser->priv->blocked_weekdays[weekday];
 }
 
 /**
- * e_weekday_chooser_set_blocked_days:
+ * e_weekday_chooser_set_blocked:
  * @chooser: an #EWeekdayChooser
- * @blocked_day_mask: Bitmask with the days to be blocked.
+ * @weekday: a #GDateWeekday
+ * @blocked: blocked flag
  *
- * Sets the days that the @chooser will prevent from being modified by
- * the user.  The @blocked_day_mask is specified in the same way as in
- * e_weekday_chooser_set_days().
+ * Sets whether @weekday is blocked from being modified by the user.
  **/
 void
-e_weekday_chooser_set_blocked_days (EWeekdayChooser *chooser,
-                                    guint8 blocked_day_mask)
+e_weekday_chooser_set_blocked (EWeekdayChooser *chooser,
+                               GDateWeekday weekday,
+                               gboolean blocked)
 {
        g_return_if_fail (E_IS_WEEKDAY_CHOOSER (chooser));
+       g_return_if_fail (g_date_valid_weekday (weekday));
 
-       chooser->priv->blocked_day_mask = blocked_day_mask;
+       chooser->priv->blocked_weekdays[weekday] = blocked;
 }
 
 /**
@@ -653,10 +629,9 @@ e_weekday_chooser_set_blocked_days (EWeekdayChooser *chooser,
  *
  * Queries the day that defines the start of the week in @chooser.
  *
- * Return value: Index of the day that defines the start of the week.  See
- * weekday_chooser_set_week_start_day() to see how this is represented.
+ * Returns: a #GDateWeekday
  **/
-gint
+GDateWeekday
 e_weekday_chooser_get_week_start_day (EWeekdayChooser *chooser)
 {
        g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), -1);
@@ -667,17 +642,16 @@ e_weekday_chooser_get_week_start_day (EWeekdayChooser *chooser)
 /**
  * e_weekday_chooser_set_week_start_day:
  * @chooser: an #EWeekdayChooser
- * @week_start_day: Index of the day that defines the start of the week; 0 is
- * Sunday, 1 is Monday, etc.
+ * @week_start_day: a #GDateWeekday
  *
  * Sets the day that defines the start of the week for @chooser.
  **/
 void
 e_weekday_chooser_set_week_start_day (EWeekdayChooser *chooser,
-                                      gint week_start_day)
+                                      GDateWeekday week_start_day)
 {
        g_return_if_fail (E_IS_WEEKDAY_CHOOSER (chooser));
-       g_return_if_fail (week_start_day >= 0 && week_start_day < 7);
+       g_return_if_fail (g_date_valid_weekday (week_start_day));
 
        if (week_start_day == chooser->priv->week_start_day)
                return;
diff --git a/calendar/gui/e-weekday-chooser.h b/calendar/gui/e-weekday-chooser.h
index cde70e4..1d28830 100644
--- a/calendar/gui/e-weekday-chooser.h
+++ b/calendar/gui/e-weekday-chooser.h
@@ -59,19 +59,21 @@ struct _EWeekdayChooserClass {
 
 GType          e_weekday_chooser_get_type      (void) G_GNUC_CONST;
 GtkWidget *    e_weekday_chooser_new           (void);
-guint8         e_weekday_chooser_get_days      (EWeekdayChooser *chooser);
-void           e_weekday_chooser_set_days      (EWeekdayChooser *chooser,
-                                                guint8 day_mask);
-guint          e_weekday_chooser_get_blocked_days
-                                               (EWeekdayChooser *chooser);
-void           e_weekday_chooser_set_blocked_days
-                                               (EWeekdayChooser *chooser,
-                                                guint8 blocked_day_mask);
-gint           e_weekday_chooser_get_week_start_day
+gboolean       e_weekday_chooser_get_selected  (EWeekdayChooser *chooser,
+                                                GDateWeekday weekday);
+void           e_weekday_chooser_set_selected  (EWeekdayChooser *chooser,
+                                                GDateWeekday weekday,
+                                                gboolean selected);
+gboolean       e_weekday_chooser_get_blocked   (EWeekdayChooser *chooser,
+                                                GDateWeekday weekday);
+void           e_weekday_chooser_set_blocked   (EWeekdayChooser *chooser,
+                                                GDateWeekday weekday,
+                                                gboolean blocked);
+GDateWeekday   e_weekday_chooser_get_week_start_day
                                                (EWeekdayChooser *chooser);
 void           e_weekday_chooser_set_week_start_day
                                                (EWeekdayChooser *chooser,
-                                                gint week_start_day);
+                                                GDateWeekday week_start_day);
 
 G_END_DECLS
 
diff --git a/calendar/gui/ea-week-view-cell.c b/calendar/gui/ea-week-view-cell.c
index 6ef8e15..ff83c00 100644
--- a/calendar/gui/ea-week-view-cell.c
+++ b/calendar/gui/ea-week-view-cell.c
@@ -221,7 +221,8 @@ ea_week_view_cell_get_name (AtkObject *accessible)
                gchar *new_name;
                const gchar *row_label, *column_label;
                gint new_column, new_row;
-               gint start_day;
+               GDateWeekday start_day;
+               gint offset;
 
                atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
                g_obj = atk_gobject_accessible_get_object (atk_gobj);
@@ -232,12 +233,14 @@ ea_week_view_cell_get_name (AtkObject *accessible)
                main_item = cell->week_view->main_canvas_item;
                ea_main_item = atk_gobject_accessible_for_object (G_OBJECT (main_item));
 
-               start_day = cell->week_view->display_start_day;
-               if (cell->column + start_day >= 7) {
-                       new_column = cell->column + start_day - 7;
+               start_day = e_week_view_get_display_start_day (cell->week_view);
+               offset = (start_day - G_DATE_MONDAY);
+
+               if (cell->column + offset >= 7) {
+                       new_column = cell->column + offset - 7;
                        new_row = cell->row + 1;
                } else {
-                       new_column = cell->column + start_day;
+                       new_column = cell->column + offset;
                        new_row = cell->row;
                }
 
@@ -359,7 +362,7 @@ component_interface_get_extents (AtkComponent *component,
        gboolean compress_weekend;
        gint week_view_width, week_view_height;
        gint scroll_x, scroll_y;
-       gint start_day;
+       GDateWeekday start_day;
 
        *x = *y = *width = *height = 0;
 
@@ -385,19 +388,19 @@ component_interface_get_extents (AtkComponent *component,
        gnome_canvas_get_scroll_offsets (
                GNOME_CANVAS (week_view->main_canvas),
                &scroll_x, &scroll_y);
-       start_day = week_view->display_start_day;
+       start_day = e_week_view_get_display_start_day (week_view);
        if (e_week_view_get_multi_week_view (week_view)) {
-               if (compress_weekend && (cell->column == (5 - start_day))) {
+               if (compress_weekend && (cell->column == e_weekday_get_days_between (start_day, 
G_DATE_SATURDAY))) {
                        *height = week_view->row_heights[cell->row*2];
                        *width = week_view->col_widths[cell->column];
                        *x += week_view->col_offsets[cell->column] - scroll_x;
                        *y += week_view->row_offsets[cell->row*2]- scroll_y;
-               } else if (compress_weekend && (cell->column == (6 - start_day))) {
+               } else if (compress_weekend && (cell->column == e_weekday_get_days_between (start_day, 
G_DATE_SUNDAY))) {
                        *height = week_view->row_heights[cell->row*2];
                        *width = week_view->col_widths[cell->column - 1];
                        *x += week_view->col_offsets[cell->column - 1]- scroll_x;
                        *y += week_view->row_offsets[cell->row*2 + 1]- scroll_y;
-               } else if (compress_weekend && (cell->column > (6 - start_day))) {
+               } else if (compress_weekend && (cell->column > e_weekday_get_days_between (start_day, 
G_DATE_SUNDAY))) {
                        *height = week_view->row_heights[cell->row*2]*2;
                        *width = week_view->col_widths[cell->column - 1];
                        *x += week_view->col_offsets[cell->column - 1] - scroll_x;
@@ -409,24 +412,24 @@ component_interface_get_extents (AtkComponent *component,
                        *y += week_view->row_offsets[cell->row*2]- scroll_y;
                }
        } else {
-               if (start_day < 3) {
+               if (start_day < G_DATE_THURSDAY) {
                        if (cell->column < 3) {
                                *height = week_view->row_heights[cell->column*2]*2;
                                *width = week_view->col_widths[0];
                                *x += week_view->col_offsets[0] - scroll_x;
                                *y += week_view->row_offsets[cell->column*2]- scroll_y;
                        } else {
-                               if (cell->column == 5 - start_day) {
+                               if (cell->column == e_weekday_get_days_between (start_day, G_DATE_SATURDAY)) {
                                        *height = week_view->row_heights[(cell->column - 3)*2];
                                        *width = week_view->col_widths[1];
                                        *x += week_view->col_offsets[1] - scroll_x;
                                        *y += week_view->row_offsets[(cell->column - 3)*2]- scroll_y;
-                               } else if (cell->column == 6 - start_day) {
+                               } else if (cell->column == e_weekday_get_days_between (start_day, 
G_DATE_SUNDAY)) {
                                        *height = week_view->row_heights[(cell->column - 4)*2];
                                        *width = week_view->col_widths[1];
                                        *x += week_view->col_offsets[1] - scroll_x;
                                        *y += week_view->row_offsets[(cell->column - 3)*2 - 1]- scroll_y;
-                               } else if (cell->column > 6 - start_day) {
+                               } else if (cell->column > e_weekday_get_days_between (start_day, 
G_DATE_SUNDAY)) {
                                        *height = week_view->row_heights[(cell->column - 4)*2]*2;
                                        *width = week_view->col_widths[1];
                                        *x += week_view->col_offsets[1] - scroll_x;
@@ -439,17 +442,17 @@ component_interface_get_extents (AtkComponent *component,
                                }
                        }
                } else if (cell->column < 4) {
-                       if (cell->column == 5 - start_day) {
+                       if (cell->column == e_weekday_get_days_between (start_day, G_DATE_SATURDAY)) {
                                *height = week_view->row_heights[cell->column*2];
                                *width = week_view->col_widths[0];
                                *x += week_view->col_offsets[0] - scroll_x;
                                *y += week_view->row_offsets[cell->column*2]- scroll_y;
-                       } else if (cell->column == 6 - start_day) {
+                       } else if (cell->column == e_weekday_get_days_between (start_day, G_DATE_SUNDAY)) {
                                *height = week_view->row_heights[(cell->column - 1)*2];
                                *width = week_view->col_widths[0];
                                *x += week_view->col_offsets[0] - scroll_x;
                                *y += week_view->row_offsets[cell->column*2 - 1]- scroll_y;
-                       } else if (cell->column > 6 - start_day) {
+                       } else if (cell->column > e_weekday_get_days_between (start_day, G_DATE_SUNDAY)) {
                                *height = week_view->row_heights[(cell->column - 1)*2]*2;
                                *width = week_view->col_widths[0];
                                *x += week_view->col_offsets[0] - scroll_x;
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index bcf0fb7..c464eef 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -927,12 +927,13 @@ get_times_for_views (GnomeCalendar *gcal,
        ECalModel *model;
        EDayView *day_view;
        EWeekView *week_view;
-       gint shown, display_start;
+       gint shown;
        GDate date;
        gint days_shown;
        GDateWeekday week_start_day;
        GDateWeekday first_work_day;
        GDateWeekday last_work_day;
+       GDateWeekday start_day;
        GDateWeekday weekday;
        guint offset;
        struct icaltimetype tt = icaltime_null_time ();
@@ -943,7 +944,7 @@ get_times_for_views (GnomeCalendar *gcal,
        range_selected = gnome_calendar_get_range_selected (gcal);
 
        timezone = e_cal_model_get_timezone (model);
-       week_start_day = e_cal_model_get_week_start_day (model) + 1;
+       week_start_day = e_cal_model_get_week_start_day (model);
 
        priv = gcal->priv;
 
@@ -1004,13 +1005,13 @@ get_times_for_views (GnomeCalendar *gcal,
                        time (select_time);
                break;
        case GNOME_CAL_WEEK_VIEW:
-               /* FIXME We should be using the same day
-                *       of the week enum everywhere. */
                week_view = E_WEEK_VIEW (priv->views[view_type]);
-               display_start = (week_view->display_start_day + 1) % 7;
+               start_day = e_week_view_get_display_start_day (week_view);
 
                *start_time = time_week_begin_with_zone (
-                       *start_time, display_start, timezone);
+                       *start_time,
+                       e_weekday_to_tm_wday (start_day),
+                       timezone);
                *end_time = time_add_week_with_zone (
                        *start_time, 1, timezone);
 
@@ -1018,19 +1019,20 @@ get_times_for_views (GnomeCalendar *gcal,
                        time (select_time);
                break;
        case GNOME_CAL_MONTH_VIEW:
-               /* FIXME We should be using the same day
-                *       of the week enum everywhere. */
                week_view = E_WEEK_VIEW (priv->views[view_type]);
                shown = e_week_view_get_weeks_shown (week_view);
-               display_start = (week_view->display_start_day + 1) % 7;
+               start_day = e_week_view_get_display_start_day (week_view);
 
                if (!range_selected && (
                        !e_week_view_get_multi_week_view (week_view) ||
                        !week_view->month_scroll_by_week))
                        *start_time = time_month_begin_with_zone (
                                *start_time, timezone);
+
                *start_time = time_week_begin_with_zone (
-                       *start_time, display_start, timezone);
+                       *start_time,
+                       e_weekday_to_tm_wday (start_day),
+                       timezone);
                *end_time = time_add_week_with_zone (
                        *start_time, shown, timezone);
 
@@ -1621,8 +1623,8 @@ gnome_calendar_goto_date (GnomeCalendar *gcal,
                           GnomeCalendarGotoDateType goto_date)
 {
        ECalModel *model;
-       time_t   new_time = 0;
-       gint week_start_day;
+       time_t new_time = 0;
+       GDateWeekday week_start_day;
        gboolean need_updating = FALSE;
        icaltimezone *timezone;
 
@@ -1654,12 +1656,16 @@ gnome_calendar_goto_date (GnomeCalendar *gcal,
                break;
        case GNOME_CAL_GOTO_FIRST_DAY_OF_WEEK:
                new_time = time_week_begin_with_zone (
-                       gcal->priv->base_view_time, week_start_day, timezone);
+                       gcal->priv->base_view_time,
+                       e_weekday_to_tm_wday (week_start_day),
+                       timezone);
                need_updating = TRUE;
                break;
        case GNOME_CAL_GOTO_LAST_DAY_OF_WEEK:
                new_time = time_week_begin_with_zone (
-                       gcal->priv->base_view_time, week_start_day, timezone);
+                       gcal->priv->base_view_time,
+                       e_weekday_to_tm_wday (week_start_day),
+                       timezone);
                if (gcal->priv->current_view_type == GNOME_CAL_DAY_VIEW ||
                    gcal->priv->current_view_type == GNOME_CAL_WORK_WEEK_VIEW) {
                        /* FIXME Shouldn't hard code work week end */
diff --git a/calendar/gui/print.c b/calendar/gui/print.c
index 0e60f84..7b9df15 100644
--- a/calendar/gui/print.c
+++ b/calendar/gui/print.c
@@ -211,8 +211,7 @@ struct pdinfo
        icaltimezone *zone;
 };
 
-struct psinfo
-{
+struct psinfo {
        gint days_shown;
        time_t day_starts[E_WEEK_VIEW_MAX_WEEKS * 7 + 1];
 
@@ -220,7 +219,7 @@ struct psinfo
 
        gint rows_per_cell;
        gint rows_per_compressed_cell;
-       gint display_start_weekday;
+       GDateWeekday display_start_weekday;
        gboolean multi_week_view;
        gint weeks_shown;
        gint month;
@@ -268,7 +267,10 @@ build_month (ECalModel *model,
              gint *end)
 {
        gint i;
-       gint d_month, d_week, week_start_day;
+       gint d_month;
+       gint d_week;
+       GDateWeekday weekday;
+       GDateWeekday week_start_day;
 
        /* Note that months are zero-based, so September is month 8 */
 
@@ -292,17 +294,16 @@ build_month (ECalModel *model,
        d_week = time_day_of_week (1, month, year);
 
        /* Get the configuration setting specifying which weekday we put on
-        * the left column, 0=Sun to 6=Sat. */
+        * the left column. */
        week_start_day = e_cal_model_get_week_start_day (model);
 
-       /* Figure out which square we want to put the 1 in. */
-       d_week = (d_week + 7 - week_start_day) % 7;
+       weekday = e_weekday_from_tm_wday (d_week);
 
        for (i = 0; i < d_month; i++)
                days[d_week + i] = i + 1;
 
        if (start)
-               *start = d_week;
+               *start = e_weekday_get_days_between (week_start_day, weekday);
 
        if (end)
                *end = d_week + d_month - 1;
@@ -716,10 +717,18 @@ instance_cb (ECalComponent *comp,
        return FALSE;
 }
 
-const gchar *daynames[] =
-/* Translators: These are workday abbreviations, e.g. Su=Sunday and Th=thursday */
-       { N_("Su"), N_("Mo"), N_("Tu"), N_("We"),
-         N_("Th"), N_("Fr"), N_("Sa") };
+const gchar *daynames[] = {
+       /* Translators: These are workday abbreviations,
+        * e.g. Su=Sunday and Th=thursday */
+       /* G_DATE_BAD_WEEKDAY */ "",
+       /* G_DATE_MONDAY      */ N_("Mo"),
+       /* G_DATE_TUESDAY     */ N_("Tu"),
+       /* G_DATE_WEDNESDAY   */ N_("We"),
+       /* G_DATE_THURSDAY    */ N_("Th"),
+       /* G_DATE_FRIDAY      */ N_("Fr"),
+       /* G_DATE_SATURDAY    */ N_("Sa"),
+       /* G_DATE_SUNDAY      */ N_("Su")
+};
 
 static gdouble
 calc_small_month_width (GtkPrintContext *context,
@@ -733,7 +742,7 @@ calc_small_month_width (GtkPrintContext *context,
        font_bold = get_font_for_size (for_height / 7.4, PANGO_WEIGHT_BOLD);
        res = MAX (evo_calendar_print_renderer_get_width (
                context, font_bold, "23"), res);
-       for (ii = 0; ii < 7; ii++) {
+       for (ii = G_DATE_MONDAY; ii < G_N_ELEMENTS (daynames); ii++) {
                res = MAX (evo_calendar_print_renderer_get_width (
                        context, font_bold, _(daynames[ii])), res);
        }
@@ -771,8 +780,10 @@ print_month_small (GtkPrintContext *context,
        ECalModel *model;
        time_t now, next;
        gint x, y;
+       gint day;
        gint days[42];
-       gint day, weekday, week_start_day;
+       GDateWeekday weekday;
+       GDateWeekday week_start_day;
        gchar buf[100];
        struct tm tm;
        gdouble font_size;
@@ -837,7 +848,7 @@ print_month_small (GtkPrintContext *context,
                        x1 + (x + (week_numbers ? 1 : 0)) * col_width,
                        x1 + (x + 1 + (week_numbers ? 1 : 0)) * col_width,
                        y1, y1 + row_height * 1.4);
-               weekday = (weekday + 1) % 7;
+               weekday = e_weekday_get_next (weekday);
        }
 
        y1 += row_height * 1.4;
@@ -866,9 +877,11 @@ print_month_small (GtkPrintContext *context,
 
                        if (day != 0) {
                                time_t week_begin;
+                               gint wday;
 
+                               wday = e_weekday_to_tm_wday (week_start_day);
                                week_begin = time_week_begin_with_zone (
-                                       now, week_start_day, zone);
+                                       now, wday, zone);
 
                                convert_timet_to_struct_tm (
                                        week_begin, zone, &tm);
@@ -1895,8 +1908,8 @@ print_week_event (GtkPrintContext *context,
                span = &g_array_index (spans, EWeekViewEventSpan,
                                       event->spans_index + span_num);
 
-               if (e_week_view_layout_get_span_position
-                   (event, span,
+               if (e_week_view_layout_get_span_position (
+                    event, span,
                     psi->rows_per_cell,
                     psi->rows_per_compressed_cell,
                     psi->display_start_weekday,
@@ -1952,25 +1965,31 @@ print_week_event (GtkPrintContext *context,
                } else {
                        cairo_t *cr = gtk_print_context_get_cairo_context (context);
 
-                       e_week_view_layout_get_day_position
-                               (span->start_day,
-                                psi->multi_week_view,
-                                psi->weeks_shown,
-                                psi->display_start_weekday,
-                                psi->compress_weekend,
-                                &start_x, &start_y, &start_h);
+                       e_week_view_layout_get_day_position (
+                               span->start_day,
+                               psi->multi_week_view,
+                               psi->weeks_shown,
+                               psi->display_start_weekday,
+                               psi->compress_weekend,
+                               &start_x, &start_y, &start_h);
 
                        y1 = top + start_y * cell_height
                                 + psi->header_row_height
                                 + psi->rows_per_cell * (psi->row_height + 2);
 
                        if (span->row >= psi->rows_per_compressed_cell && psi->compress_weekend) {
-                               gint end_day_of_week =
-                                       (psi->display_start_weekday +
-                                        span->start_day) % 7;
+                               GDateWeekday end_weekday;
+                               gboolean end_on_weekend;
+
+                               end_weekday = e_weekday_add_days (
+                                       psi->display_start_weekday,
+                                       span->start_day);
 
-                               if (end_day_of_week == 5 || end_day_of_week == 6) {
-                                       /* Sat or Sun */
+                               end_on_weekend =
+                                       (end_weekday == G_DATE_SATURDAY) ||
+                                       (end_weekday == G_DATE_SUNDAY);
+
+                               if (end_on_weekend) {
                                        y1 = top + start_y * cell_height
                                                 + psi->header_row_height
                                                 + psi->rows_per_compressed_cell * (psi->row_height + 2);
@@ -2167,13 +2186,11 @@ print_week_summary (GtkPrintContext *context,
                psi.compress_weekend = TRUE;
        psi.use_24_hour_format = e_cal_model_get_use_24_hour_format (model);
 
-       /* We convert this from (0 = Sun, 6 = Sat) to (0 = Mon, 6 = Sun). */
        psi.display_start_weekday = e_cal_model_get_week_start_day (model);
-       psi.display_start_weekday = (psi.display_start_weekday + 6) % 7;
 
        /* If weekends are compressed then we can't start on a Sunday. */
-       if (psi.compress_weekend && psi.display_start_weekday == 6)
-               psi.display_start_weekday = 5;
+       if (psi.compress_weekend && psi.display_start_weekday == G_DATE_SUNDAY)
+               psi.display_start_weekday = G_DATE_SATURDAY;
 
        day_start = time_day_begin_with_zone (whence, zone);
        for (day = 0; day <= psi.days_shown; day++) {
@@ -2184,8 +2201,8 @@ print_week_summary (GtkPrintContext *context,
        /* Get the events from the server. */
        e_cal_model_generate_instances_sync (
                model,
-                                       psi.day_starts[0], psi.day_starts[psi.days_shown],
-                                       print_week_summary_cb, &psi);
+               psi.day_starts[0], psi.day_starts[psi.days_shown],
+               print_week_summary_cb, &psi);
        qsort (
                psi.events->data, psi.events->len,
                sizeof (EWeekViewEvent), e_week_view_event_sort_func);
@@ -2263,7 +2280,9 @@ print_month_summary (GtkPrintContext *context,
        ECalModel *model;
        PangoFontDescription *font;
        gboolean compress_weekend;
-       gint columns, col, weekday, month, weeks;
+       gint columns, col, month, weeks;
+       GDateWeekday weekday;
+       gint wday;
        gdouble font_size, cell_width, x1, x2, y1, y2;
 
        model = gnome_calendar_get_model (gcal);
@@ -2303,10 +2322,12 @@ print_month_summary (GtkPrintContext *context,
         * or before that day. */
        if (!date)
                date = time_month_begin_with_zone (whence, zone);
-       date = time_week_begin_with_zone (date, weekday, zone);
+
+       wday = e_weekday_to_tm_wday (weekday);
+       date = time_week_begin_with_zone (date, wday, zone);
 
        /* If weekends are compressed then we can't start on a Sunday. */
-       if (compress_weekend && weekday == 0)
+       if (compress_weekend && weekday == G_DATE_SUNDAY)
                date = time_add_day_with_zone (date, -1, zone);
 
        /* do day names ... */
@@ -3027,7 +3048,8 @@ print_week_view (GtkPrintContext *context,
        gdouble l, week_numbers_inc, small_month_width;
        gchar buf[100];
        time_t when;
-       gint week_start_day;
+       GDateWeekday week_start_day;
+       gint wday;
        struct tm tm;
        gdouble width, height;
 
@@ -3043,11 +3065,13 @@ print_week_view (GtkPrintContext *context,
 
        convert_timet_to_struct_tm (date, zone, &tm);
        week_start_day = e_cal_model_get_week_start_day (model);
-       when = time_week_begin_with_zone (date, week_start_day, zone);
+
+       wday = e_weekday_to_tm_wday (week_start_day);
+       when = time_week_begin_with_zone (date, wday, zone);
 
        /* If the week starts on a Sunday, we have to show the Saturday first,
         * since the weekend is compressed. */
-       if (week_start_day == 0) {
+       if (week_start_day == G_DATE_SUNDAY) {
                if (tm.tm_wday == 6)
                        when = time_add_day_with_zone (when, 6, zone);
                else
diff --git a/e-util/e-calendar-item.c b/e-util/e-calendar-item.c
index 3e77154..eed5ad3 100644
--- a/e-util/e-calendar-item.c
+++ b/e-util/e-calendar-item.c
@@ -38,6 +38,7 @@
 
 #include "ea-widgets.h"
 #include "e-misc-utils.h"
+#include "e-util-enumtypes.h"
 
 static const gint e_calendar_item_days_in_month[12] = {
        31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
@@ -84,7 +85,7 @@ static void   e_calendar_item_draw_day_numbers
                                                 gint col,
                                                 gint year,
                                                 gint month,
-                                                gint start_weekday,
+                                                GDateWeekday start_weekday,
                                                 gint cells_x,
                                                 gint cells_y);
 static GnomeCanvasItem *e_calendar_item_point  (GnomeCanvasItem *item,
@@ -446,14 +447,14 @@ e_calendar_item_class_init (ECalendarItemClass *class)
        g_object_class_install_property (
                object_class,
                PROP_WEEK_START_DAY,
-               g_param_spec_int (
-                       "week_start_day",
+               g_param_spec_enum (
+                       "week-start-day",
                        NULL,
                        NULL,
-                       G_MININT,
-                       G_MAXINT,
-                       0,
-                       G_PARAM_READWRITE));
+                       E_TYPE_DATE_WEEKDAY,
+                       G_DATE_MONDAY,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS));
 
        g_object_class_install_property (
                object_class,
@@ -583,7 +584,7 @@ e_calendar_item_init (ECalendarItem *calitem)
 
        calitem->show_week_numbers = FALSE;
        calitem->keep_wdays_on_weeknum_click = FALSE;
-       calitem->week_start_day = 0;
+       calitem->week_start_day = G_DATE_MONDAY;
        calitem->expand = TRUE;
        calitem->max_days_selected = 1;
        calitem->days_to_start_week_selection = -1;
@@ -707,7 +708,7 @@ e_calendar_item_get_property (GObject *object,
                g_value_set_int (value, calitem->max_cols);
                return;
        case PROP_WEEK_START_DAY:
-               g_value_set_int (value, calitem->week_start_day);
+               g_value_set_enum (value, calitem->week_start_day);
                return;
        case PROP_SHOW_WEEK_NUMBERS:
                g_value_set_boolean (value, calitem->show_week_numbers);
@@ -835,7 +836,7 @@ e_calendar_item_set_property (GObject *object,
                }
                return;
        case PROP_WEEK_START_DAY:
-               ivalue = g_value_get_int (value);
+               ivalue = g_value_get_enum (value);
                if (calitem->week_start_day != ivalue) {
                        calitem->week_start_day = ivalue;
                        gnome_canvas_item_request_update (item);
@@ -1186,12 +1187,11 @@ e_calendar_item_draw (GnomeCanvasItem *canvas_item,
 static void
 layout_set_day_text (ECalendarItem *calitem,
                      PangoLayout *layout,
-                     gint day_index)
+                     GDateWeekday weekday)
 {
        const gchar *abbr_name;
 
-       /* day_index: 0 = Monday ... 6 = Sunday */
-       abbr_name = e_get_weekday_name (day_index + 1, TRUE);
+       abbr_name = e_get_weekday_name (weekday, TRUE);
        pango_layout_set_text (layout, abbr_name, -1);
 }
 
@@ -1211,13 +1211,15 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
        PangoFontDescription *font_desc;
        struct tm tmp_tm;
        GdkRectangle clip_rect;
-       gint char_height, xthickness, ythickness, start_weekday;
+       GDateWeekday start_weekday;
+       gint char_height, xthickness, ythickness;
        gint year, month;
        gint month_x, month_y, month_w, month_h;
        gint min_x, max_x, text_x, text_y;
-       gint day, day_index, cells_x, cells_y, min_cell_width, text_width, arrow_button_size;
+       gint day, cells_x, cells_y, min_cell_width, text_width, arrow_button_size;
        gint clip_width, clip_height;
        gchar buffer[64];
+       GDateWeekday weekday;
        PangoContext *pango_context;
        PangoFontMetrics *font_metrics;
        PangoLayout *layout;
@@ -1301,7 +1303,8 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
        tmp_tm.tm_mday = 1;
        tmp_tm.tm_isdst = -1;
        mktime (&tmp_tm);
-       start_weekday = (tmp_tm.tm_wday + 6) % 7;
+
+       start_weekday = e_weekday_from_tm_wday (tmp_tm.tm_wday);
 
        if (month_x + max_x - clip_rect.x > 0) {
                cairo_save (cr);
@@ -1427,25 +1430,24 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
        cairo_fill (cr);
        cairo_restore (cr);
 
-       day_index = calitem->week_start_day;
+       weekday = calitem->week_start_day;
        pango_layout_set_font_description (layout, font_desc);
        if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
                text_x += (7 - 1) * calitem->cell_width;
        gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_ACTIVE]);
        for (day = 0; day < 7; day++) {
                cairo_save (cr);
-               layout_set_day_text (calitem, layout, day_index);
+               layout_set_day_text (calitem, layout, weekday);
                cairo_move_to (
                        cr,
-                       text_x - calitem->day_widths[day_index],
+                       text_x - calitem->day_widths[weekday],
                        text_y);
                pango_cairo_show_layout (cr, layout);
                text_x += (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
                                ? -calitem->cell_width : calitem->cell_width;
-               day_index++;
-               if (day_index == 7)
-                       day_index = 0;
                cairo_restore (cr);
+
+               weekday = e_weekday_get_next (weekday);
        }
 
        /* Draw the rectangle around the week number. */
@@ -1504,7 +1506,7 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
                                   gint col,
                                   gint year,
                                   gint month,
-                                  gint start_weekday,
+                                  GDateWeekday start_weekday,
                                   gint cells_x,
                                   gint cells_y)
 {
@@ -1579,8 +1581,8 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
 
        month_offset = row * calitem->cols + col - 1;
        day_num = days_in_month[0];
-       days_from_week_start = (start_weekday + 7 - calitem->week_start_day)
-               % 7;
+       days_from_week_start = e_weekday_get_days_between (
+               calitem->week_start_day, start_weekday);
        /* For the top-left month we show the end of the previous month, and
         * if the new month starts on the first day of the week we show a
         * complete week from the previous month. */
@@ -1838,23 +1840,29 @@ e_calendar_item_get_week_number (ECalendarItem *calitem,
                                  gint year)
 {
        GDate date;
-       guint weekday, yearday;
+       GDateWeekday weekday;
+       guint yearday;
        gint week_num;
 
        g_date_clear (&date, 1);
        g_date_set_dmy (&date, day, month + 1, year);
 
-       /* This results in a value of 0 (Monday) - 6 (Sunday).
-        * (or -1 on error - oops!!) */
-       weekday = g_date_get_weekday (&date) - 1;
+       weekday = g_date_get_weekday (&date);
+
+       if (g_date_valid_weekday (weekday)) {
+               guint days_between;
 
-       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);
+               /* We want always point to nearest Monday as the first day
+                * of the week regardless of the calendar's week_start_day. */
+               if (weekday >= G_DATE_THURSDAY) {
+                       days_between = e_weekday_get_days_between (
+                               weekday, G_DATE_MONDAY);
+                       g_date_add_days (&date, days_between);
+               } else {
+                       days_between = e_weekday_get_days_between (
+                               G_DATE_MONDAY, weekday);
+                       g_date_subtract_days (&date, days_between);
+               }
        }
 
        /* Calculate the day of the year, from 0 to 365. */
@@ -2079,7 +2087,7 @@ e_calendar_item_recalc_sizes (ECalendarItem *calitem)
 {
        GnomeCanvasItem *canvas_item;
        GtkStyle *style;
-       gint day, max_day_width, digit, max_digit_width, max_week_number_digit_width;
+       gint max_day_width, digit, max_digit_width, max_week_number_digit_width;
        gint char_height, width, min_cell_width, min_cell_height;
        gchar buffer[64];
        struct tm tmp_tm;
@@ -2087,6 +2095,7 @@ e_calendar_item_recalc_sizes (ECalendarItem *calitem)
        PangoContext *pango_context;
        PangoFontMetrics *font_metrics;
        PangoLayout *layout;
+       GDateWeekday weekday;
 
        canvas_item = GNOME_CANVAS_ITEM (calitem);
        style = gtk_widget_get_style (GTK_WIDGET (canvas_item->canvas));
@@ -2112,11 +2121,11 @@ e_calendar_item_recalc_sizes (ECalendarItem *calitem)
                PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics));
 
        max_day_width = 0;
-       for (day = 0; day < 7; day++) {
-               layout_set_day_text (calitem, layout, day);
+       for (weekday = G_DATE_MONDAY; weekday <= G_DATE_SUNDAY; weekday++) {
+               layout_set_day_text (calitem, layout, weekday);
                pango_layout_get_pixel_size (layout, &width, NULL);
 
-               calitem->day_widths[day] = width;
+               calitem->day_widths[weekday] = width;
                max_day_width = MAX (max_day_width, width);
        }
        calitem->max_day_width = max_day_width;
@@ -2742,7 +2751,8 @@ e_calendar_item_get_month_info (ECalendarItem *calitem,
                                 gint *days_in_month,
                                 gint *days_in_prev_month)
 {
-       gint year, month, start_weekday, first_day_of_month;
+       GDateWeekday start_weekday;
+       gint year, month, first_day_of_month;
        struct tm tmp_tm = { 0 };
 
        month = calitem->month + row * calitem->cols + col;
@@ -2761,10 +2771,10 @@ e_calendar_item_get_month_info (ECalendarItem *calitem,
        tmp_tm.tm_isdst = -1;
        mktime (&tmp_tm);
 
-       /* Convert to 0 (Monday) to 6 (Sunday). */
-       start_weekday = (tmp_tm.tm_wday + 6) % 7;
+       start_weekday = e_weekday_from_tm_wday (tmp_tm.tm_wday);
 
-       first_day_of_month = (start_weekday + 7 - calitem->week_start_day) % 7;
+       first_day_of_month = e_weekday_get_days_between (
+               calitem->week_start_day, start_weekday);
 
        if (row == 0 && col == 0 && first_day_of_month == 0)
                *first_day_offset = 7;
@@ -3177,7 +3187,8 @@ e_calendar_item_round_up_selection (ECalendarItem *calitem,
                                     gint *month_offset,
                                     gint *day)
 {
-       gint year, month, weekday, days, days_in_month;
+       GDateWeekday weekday;
+       gint year, month, days, days_in_month;
        struct tm tmp_tm = { 0 };
 
        year = calitem->year;
@@ -3190,11 +3201,9 @@ e_calendar_item_round_up_selection (ECalendarItem *calitem,
        tmp_tm.tm_isdst = -1;
        mktime (&tmp_tm);
 
-       /* Convert to 0 (Monday) to 6 (Sunday). */
-       weekday = (tmp_tm.tm_wday + 6) % 7;
-
        /* Calculate how many days to the end of the row. */
-       days = (calitem->week_start_day + 6 - weekday) % 7;
+       weekday = e_weekday_from_tm_wday (tmp_tm.tm_wday);
+       days = e_weekday_get_days_between (weekday, calitem->week_start_day);
 
        *day += days;
        days_in_month = DAYS_IN_MONTH (year, month);
@@ -3210,7 +3219,8 @@ e_calendar_item_round_down_selection (ECalendarItem *calitem,
                                       gint *month_offset,
                                       gint *day)
 {
-       gint year, month, weekday, days, days_in_month;
+       GDateWeekday weekday;
+       gint year, month, days, days_in_month;
        struct tm tmp_tm = { 0 };
 
        year = calitem->year;
@@ -3223,11 +3233,9 @@ e_calendar_item_round_down_selection (ECalendarItem *calitem,
        tmp_tm.tm_isdst = -1;
        mktime (&tmp_tm);
 
-       /* Convert to 0 (Monday) to 6 (Sunday). */
-       weekday = (tmp_tm.tm_wday + 6) % 7;
-
        /* Calculate how many days to the start of the row. */
-       days = (weekday + 7 - calitem->week_start_day) % 7;
+       weekday = e_weekday_from_tm_wday (tmp_tm.tm_wday);
+       days = e_weekday_get_days_between (weekday, calitem->week_start_day);
 
        *day -= days;
        if (*day <= 0) {
diff --git a/e-util/e-calendar-item.h b/e-util/e-calendar-item.h
index 9a3828f..09303f1 100644
--- a/e-util/e-calendar-item.h
+++ b/e-util/e-calendar-item.h
@@ -167,8 +167,8 @@ struct _ECalendarItem {
        /* whether to keep same week days selected on week number click */
        gboolean keep_wdays_on_weeknum_click;
 
-       /* The first day of the week, 0 (Monday) to 6 (Sunday). */
-       gint week_start_day;
+       /* The first day of the week. */
+       GDateWeekday week_start_day;
 
        /* Whether the cells expand to fill extra space. */
        gboolean expand;
@@ -234,7 +234,7 @@ struct _ECalendarItem {
        gint selection_real_start_day;
 
        /* Widths of the day characters. */
-       gint day_widths[7];
+       gint day_widths[8]; /* indexed by GDateWeekday */
        gint max_day_width;
 
        /* Widths of the digits, '0' .. '9'. */
diff --git a/e-util/e-dateedit.c b/e-util/e-dateedit.c
index 0a30750..111b3ff 100644
--- a/e-util/e-dateedit.c
+++ b/e-util/e-dateedit.c
@@ -41,6 +41,7 @@
 #include <libebackend/libebackend.h>
 
 #include "e-calendar.h"
+#include "e-util-enumtypes.h"
 
 #define E_DATE_EDIT_GET_PRIVATE(obj) \
        (G_TYPE_INSTANCE_GET_PRIVATE \
@@ -257,7 +258,7 @@ date_edit_set_property (GObject *object,
                case PROP_WEEK_START_DAY:
                        e_date_edit_set_week_start_day (
                                E_DATE_EDIT (object),
-                               g_value_get_int (value));
+                               g_value_get_enum (value));
                        return;
 
                case PROP_TWODIGIT_YEAR_CAN_FUTURE:
@@ -313,7 +314,7 @@ date_edit_get_property (GObject *object,
                        return;
 
                case PROP_WEEK_START_DAY:
-                       g_value_set_int (
+                       g_value_set_enum (
                                value, e_date_edit_get_week_start_day (
                                E_DATE_EDIT (object)));
                        return;
@@ -432,14 +433,14 @@ e_date_edit_class_init (EDateEditClass *class)
        g_object_class_install_property (
                object_class,
                PROP_WEEK_START_DAY,
-               g_param_spec_int (
+               g_param_spec_enum (
                        "week-start-day",
                        "Week Start Day",
                        NULL,
-                       0,  /* Monday */
-                       6,  /* Sunday */
-                       0,
-                       G_PARAM_READWRITE));
+                       E_TYPE_DATE_WEEKDAY,
+                       G_DATE_MONDAY,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS));
 
        g_object_class_install_property (
                object_class,
@@ -1209,21 +1210,21 @@ e_date_edit_set_make_time_insensitive (EDateEdit *dedit,
 /**
  * e_date_edit_get_week_start_day:
  * @dedit: an #EDateEdit
- * @Returns: the week start day, from 0 (Monday) to 6 (Sunday).
  *
- * Description: Returns the week start day currently used in the calendar
- * popup.
+ * Returns the week start day currently used in the calendar popup.
+ *
+ * Returns: a #GDateWeekday
  */
-gint
+GDateWeekday
 e_date_edit_get_week_start_day (EDateEdit *dedit)
 {
-       gint week_start_day;
+       GDateWeekday week_start_day;
 
        g_return_val_if_fail (E_IS_DATE_EDIT (dedit), 1);
 
        g_object_get (
                E_CALENDAR (dedit->priv->calendar)->calitem,
-               "week_start_day", &week_start_day, NULL);
+               "week-start-day", &week_start_day, NULL);
 
        return week_start_day;
 }
@@ -1231,19 +1232,20 @@ e_date_edit_get_week_start_day (EDateEdit *dedit)
 /**
  * e_date_edit_set_week_start_day:
  * @dedit: an #EDateEdit
- * @week_start_day: the week start day, from 0 (Monday) to 6 (Sunday).
+ * @week_start_day: a #GDateWeekday
  *
- * Description: Sets the week start day to use in the calendar popup.
+ * Sets the week start day to use in the calendar popup.
  */
 void
 e_date_edit_set_week_start_day (EDateEdit *dedit,
-                                gint week_start_day)
+                                GDateWeekday week_start_day)
 {
        g_return_if_fail (E_IS_DATE_EDIT (dedit));
+       g_return_if_fail (g_date_valid_weekday (week_start_day));
 
        gnome_canvas_item_set (
                GNOME_CANVAS_ITEM (E_CALENDAR (dedit->priv->calendar)->calitem),
-               "week_start_day", week_start_day, NULL);
+               "week-start-day", week_start_day, NULL);
 
        g_object_notify (G_OBJECT (dedit), "week-start-day");
 }
diff --git a/e-util/e-dateedit.h b/e-util/e-dateedit.h
index 5557bb1..de23a1f 100644
--- a/e-util/e-dateedit.h
+++ b/e-util/e-dateedit.h
@@ -152,10 +152,10 @@ gboolean  e_date_edit_get_show_time       (EDateEdit *dedit);
 void           e_date_edit_set_show_time       (EDateEdit *dedit,
                                                 gboolean show_time);
 
-/* The week start day, used in the date popup. 0 (Mon) to 6 (Sun). */
-gint           e_date_edit_get_week_start_day  (EDateEdit *dedit);
+/* The week start day, used in the date popup. */
+GDateWeekday   e_date_edit_get_week_start_day  (EDateEdit *dedit);
 void           e_date_edit_set_week_start_day  (EDateEdit *dedit,
-                                                gint week_start_day);
+                                                GDateWeekday week_start_day);
 
 /* Whether we show week numbers in the date popup. */
 gboolean       e_date_edit_get_show_week_numbers
diff --git a/e-util/ea-calendar-item.c b/e-util/ea-calendar-item.c
index 2f5ac91..aefcbba 100644
--- a/e-util/ea-calendar-item.c
+++ b/e-util/ea-calendar-item.c
@@ -1334,8 +1334,8 @@ e_calendar_item_get_n_days_from_week_start (ECalendarItem *calitem,
                                             gint year,
                                             gint month)
 {
+       GDateWeekday weekday;
        struct tm tmp_tm;
-       gint start_weekday, days_from_week_start;
 
        memset (&tmp_tm, 0, sizeof (tmp_tm));
        tmp_tm.tm_year = year - 1900;
@@ -1343,10 +1343,10 @@ e_calendar_item_get_n_days_from_week_start (ECalendarItem *calitem,
        tmp_tm.tm_mday = 1;
        tmp_tm.tm_isdst = -1;
        mktime (&tmp_tm);
-       start_weekday = (tmp_tm.tm_wday + 6) % 7;   /* 0 to 6 */
-       days_from_week_start = (start_weekday + 7 - calitem->week_start_day)
-               % 7;
-       return days_from_week_start;
+
+       weekday = e_weekday_from_tm_wday (tmp_tm.tm_wday);
+
+       return e_weekday_get_days_between (calitem->week_start_day, weekday);
 }
 
 static void
diff --git a/modules/calendar/e-cal-shell-settings.c b/modules/calendar/e-cal-shell-settings.c
index 7f6527b..d328840 100644
--- a/modules/calendar/e-cal-shell-settings.c
+++ b/modules/calendar/e-cal-shell-settings.c
@@ -147,31 +147,7 @@ transform_weekdays_settings_to_evolution (GBinding *binding,
        }
 
        /* Evolution numbering */
-       switch (weekday) {
-               case G_DATE_MONDAY:
-                       g_value_set_int (target_value, 0);
-                       break;
-               case G_DATE_TUESDAY:
-                       g_value_set_int (target_value, 1);
-                       break;
-               case G_DATE_WEDNESDAY:
-                       g_value_set_int (target_value, 2);
-                       break;
-               case G_DATE_THURSDAY:
-                       g_value_set_int (target_value, 3);
-                       break;
-               case G_DATE_FRIDAY:
-                       g_value_set_int (target_value, 4);
-                       break;
-               case G_DATE_SATURDAY:
-                       g_value_set_int (target_value, 5);
-                       break;
-               case G_DATE_SUNDAY:
-                       g_value_set_int (target_value, 6);
-                       break;
-               default:
-                       return FALSE;
-       }
+       g_value_set_enum (target_value, weekday);
 
        return TRUE;
 }
@@ -192,34 +168,10 @@ transform_weekdays_evolution_to_settings (GBinding *binding,
 
        /* This is purposefully verbose for better readability. */
 
-       /* setting numbering */
-       switch (g_value_get_int (source_value)) {
-               case 0:
-                       weekday = G_DATE_MONDAY;
-                       break;
-               case 1:
-                       weekday = G_DATE_TUESDAY;
-                       break;
-               case 2:
-                       weekday = G_DATE_WEDNESDAY;
-                       break;
-               case 3:
-                       weekday = G_DATE_THURSDAY;
-                       break;
-               case 4:
-                       weekday = G_DATE_FRIDAY;
-                       break;
-               case 5:
-                       weekday = G_DATE_SATURDAY;
-                       break;
-               case 6:
-                       weekday = G_DATE_SUNDAY;
-                       break;
-               default:
-                       return FALSE;
-       }
-
        /* Evolution numbering */
+       weekday = g_value_get_enum (source_value);
+
+       /* setting numbering */
        switch (weekday) {
                case G_DATE_MONDAY:
                        g_value_set_int (target_value, 1);
@@ -802,13 +754,12 @@ e_cal_shell_backend_init_settings (EShell *shell)
                (GDestroyNotify) g_object_unref);
 
        e_shell_settings_install_property (
-               g_param_spec_int (
+               g_param_spec_enum (
                        "cal-week-start-day",
                        NULL,
                        NULL,
-                       0,  /* Monday */
-                       6,  /* Sunday */
-                       0,
+                       E_TYPE_DATE_WEEKDAY,
+                       G_DATE_MONDAY,
                        G_PARAM_READWRITE));
 
        g_object_bind_property_full (
diff --git a/modules/calendar/e-cal-shell-view-private.c b/modules/calendar/e-cal-shell-view-private.c
index b8a5583..4561ad3 100644
--- a/modules/calendar/e-cal-shell-view-private.c
+++ b/modules/calendar/e-cal-shell-view-private.c
@@ -96,7 +96,7 @@ cal_shell_view_date_navigator_selection_changed_cb (ECalShellView *cal_shell_vie
        time_t start, end, new_time;
        gboolean starts_on_week_start_day;
        gint new_days_shown, old_days_shown;
-       gint week_start_day;
+       GDateWeekday week_start_day;
 
        cal_shell_content = cal_shell_view->priv->cal_shell_content;
        calendar = e_cal_shell_content_get_calendar (cal_shell_content);
@@ -125,7 +125,8 @@ cal_shell_view_date_navigator_selection_changed_cb (ECalShellView *cal_shell_vie
                multi_week_view = e_week_view_get_multi_week_view (week_view);
                compress_weekend = e_week_view_get_compress_weekend (week_view);
 
-               if (week_start_day == 0 && (!multi_week_view || compress_weekend))
+               if (week_start_day == G_DATE_SUNDAY &&
+                               (!multi_week_view || compress_weekend))
                        g_date_add_days (&start_date, 1);
        }
 
@@ -151,7 +152,7 @@ cal_shell_view_date_navigator_selection_changed_cb (ECalShellView *cal_shell_vie
         * day is set to Sunday, we don't actually show complete
         * weeks in the week view, so this may need tweaking. */
        starts_on_week_start_day =
-               (g_date_get_weekday (&new_start_date) % 7 == week_start_day);
+               (g_date_get_weekday (&new_start_date) == week_start_day);
 
        /* Update selection to be in the new time range. */
        tt = icaltime_null_time ();
diff --git a/modules/calendar/e-calendar-preferences.c b/modules/calendar/e-calendar-preferences.c
index 5c71fd8..0079b2c 100644
--- a/modules/calendar/e-calendar-preferences.c
+++ b/modules/calendar/e-calendar-preferences.c
@@ -584,11 +584,14 @@ calendar_preferences_construct (ECalendarPreferences *prefs,
                G_BINDING_SYNC_CREATE);
 
        widget = e_builder_get_widget (prefs->builder, "week_start_day");
-       g_object_bind_property (
+       g_object_bind_property_full (
                shell_settings, "cal-week-start-day",
-               widget, "active",
+               widget, "active-id",
                G_BINDING_BIDIRECTIONAL |
-               G_BINDING_SYNC_CREATE);
+               G_BINDING_SYNC_CREATE,
+               e_binding_transform_enum_value_to_nick,
+               e_binding_transform_enum_nick_to_value,
+               NULL, (GDestroyNotify) NULL);
 
        widget = e_builder_get_widget (prefs->builder, "start_of_day");
        prefs->start_of_day = widget;  /* XXX delete this */
diff --git a/modules/calendar/e-calendar-preferences.ui b/modules/calendar/e-calendar-preferences.ui
index cb508ae..7af3f20 100644
--- a/modules/calendar/e-calendar-preferences.ui
+++ b/modules/calendar/e-calendar-preferences.ui
@@ -19,35 +19,6 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
-  <object class="GtkListStore" id="model1">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Monday</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Tuesday</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Wednesday</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Thursday</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Friday</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Saturday</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Sunday</col>
-      </row>
-    </data>
-  </object>
   <object class="GtkListStore" id="model2">
     <columns>
       <!-- column-name gchararray -->
@@ -588,15 +559,17 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkComboBox" id="week_start_day">
+                  <object class="GtkComboBoxText" id="week_start_day">
                     <property name="visible">True</property>
-                    <property name="model">model1</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer1"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
+                    <items>
+                      <item translatable="yes" id="monday">Monday</item>
+                      <item translatable="yes" id="tuesday">Tuesday</item>
+                      <item translatable="yes" id="wednesday">Wednesday</item>
+                      <item translatable="yes" id="thursday">Thursday</item>
+                      <item translatable="yes" id="friday">Friday</item>
+                      <item translatable="yes" id="saturday">Saturday</item>
+                      <item translatable="yes" id="sunday">Sunday</item>
+                    </items>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>


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