aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-03-07 22:57:35 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-03-07 23:00:31 +0800
commit5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6 (patch)
tree9ab058b44d2e51d1e856c155727af9e6ef584be9 /e-util
parent8a3453fee1c8150336169f55261c26699084a4ce (diff)
downloadgsoc2013-evolution-5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6.tar
gsoc2013-evolution-5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6.tar.gz
gsoc2013-evolution-5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6.tar.bz2
gsoc2013-evolution-5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6.tar.lz
gsoc2013-evolution-5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6.tar.xz
gsoc2013-evolution-5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6.tar.zst
gsoc2013-evolution-5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6.zip
Add e_get_next_weekday() and e_get_prev_weekday().
These just cycle over the GDateWeekday enum. Trivial functions, but they help make loops a little easier to read.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-misc-utils.c88
-rw-r--r--e-util/e-misc-utils.h2
2 files changed, 90 insertions, 0 deletions
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index 563a69c54c..af5d6906a1 100644
--- a/e-util/e-misc-utils.c
+++ b/e-util/e-misc-utils.c
@@ -1495,6 +1495,94 @@ e_get_weekday_name (GDateWeekday weekday,
return abbreviated ? abbr_names[weekday] : full_names[weekday];
}
+/**
+ * e_get_next_weekday:
+ * @weekday: a #GDateWeekday
+ *
+ * Returns the #GDateWeekday after @weekday.
+ *
+ * Returns: the day after @weekday
+ **/
+GDateWeekday
+e_get_next_weekday (GDateWeekday weekday)
+{
+ GDateWeekday next;
+
+ /* Verbose for readability. */
+ switch (weekday) {
+ case G_DATE_MONDAY:
+ next = G_DATE_TUESDAY;
+ break;
+ case G_DATE_TUESDAY:
+ next = G_DATE_WEDNESDAY;
+ break;
+ case G_DATE_WEDNESDAY:
+ next = G_DATE_THURSDAY;
+ break;
+ case G_DATE_THURSDAY:
+ next = G_DATE_FRIDAY;
+ break;
+ case G_DATE_FRIDAY:
+ next = G_DATE_SATURDAY;
+ break;
+ case G_DATE_SATURDAY:
+ next = G_DATE_SUNDAY;
+ break;
+ case G_DATE_SUNDAY:
+ next = G_DATE_MONDAY;
+ break;
+ default:
+ next = G_DATE_BAD_WEEKDAY;
+ break;
+ }
+
+ return next;
+}
+
+/**
+ * e_get_prev_weekday:
+ * @weekday: a #GDateWeekday
+ *
+ * Returns the #GDateWeekday before @weekday.
+ *
+ * Returns: the day before @weekday
+ **/
+GDateWeekday
+e_get_prev_weekday (GDateWeekday weekday)
+{
+ GDateWeekday prev;
+
+ /* Verbose for readability. */
+ switch (weekday) {
+ case G_DATE_MONDAY:
+ prev = G_DATE_SUNDAY;
+ break;
+ case G_DATE_TUESDAY:
+ prev = G_DATE_MONDAY;
+ break;
+ case G_DATE_WEDNESDAY:
+ prev = G_DATE_TUESDAY;
+ break;
+ case G_DATE_THURSDAY:
+ prev = G_DATE_WEDNESDAY;
+ break;
+ case G_DATE_FRIDAY:
+ prev = G_DATE_THURSDAY;
+ break;
+ case G_DATE_SATURDAY:
+ prev = G_DATE_FRIDAY;
+ break;
+ case G_DATE_SUNDAY:
+ prev = G_DATE_SATURDAY;
+ break;
+ default:
+ prev = G_DATE_BAD_WEEKDAY;
+ break;
+ }
+
+ return prev;
+}
+
/* Evolution Locks for crash recovery */
static const gchar *
get_lock_filename (void)
diff --git a/e-util/e-misc-utils.h b/e-util/e-misc-utils.h
index e41689bd43..ee7e276152 100644
--- a/e-util/e-misc-utils.h
+++ b/e-util/e-misc-utils.h
@@ -139,6 +139,8 @@ const gchar * e_get_month_name (GDateMonth month,
gboolean abbreviated);
const gchar * e_get_weekday_name (GDateWeekday weekday,
gboolean abbreviated);
+GDateWeekday e_get_next_weekday (GDateWeekday weekday);
+GDateWeekday e_get_prev_weekday (GDateWeekday weekday);
gboolean e_file_lock_create (void);
void e_file_lock_destroy (void);