[evolution] Add e_get_next_weekday() and e_get_prev_weekday().



commit 5e9bdd4509614f459aaeb6b7e218f9cc7fe031a6
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Mar 7 09:57:35 2013 -0500

    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.

 doc/reference/libeutil/libeutil-sections.txt |    2 +
 e-util/e-misc-utils.c                        |   88 ++++++++++++++++++++++++++
 e-util/e-misc-utils.h                        |    2 +
 3 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/doc/reference/libeutil/libeutil-sections.txt b/doc/reference/libeutil/libeutil-sections.txt
index c09d885..6d87f8f 100644
--- a/doc/reference/libeutil/libeutil-sections.txt
+++ b/doc/reference/libeutil/libeutil-sections.txt
@@ -2247,6 +2247,8 @@ e_strftime_fix_am_pm
 e_utf8_strftime_fix_am_pm
 e_get_month_name
 e_get_weekday_name
+e_get_next_weekday
+e_get_prev_weekday
 e_flexible_strtod
 E_ASCII_DTOSTR_BUF_SIZE
 e_ascii_dtostr
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index 563a69c..af5d690 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 e41689b..ee7e276 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);


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