aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-03-09 01:39:27 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-03-09 01:39:27 +0800
commit494c98c7642acb7ca678c57678ce104da14c62a8 (patch)
tree1dd5c74c21efa583ce4323076d5e2126be7ce589 /e-util
parent379f60bc79b3fbeac6061d5c12f2d8ed65aa7c95 (diff)
downloadgsoc2013-evolution-494c98c7642acb7ca678c57678ce104da14c62a8.tar
gsoc2013-evolution-494c98c7642acb7ca678c57678ce104da14c62a8.tar.gz
gsoc2013-evolution-494c98c7642acb7ca678c57678ce104da14c62a8.tar.bz2
gsoc2013-evolution-494c98c7642acb7ca678c57678ce104da14c62a8.tar.lz
gsoc2013-evolution-494c98c7642acb7ca678c57678ce104da14c62a8.tar.xz
gsoc2013-evolution-494c98c7642acb7ca678c57678ce104da14c62a8.tar.zst
gsoc2013-evolution-494c98c7642acb7ca678c57678ce104da14c62a8.zip
Add weekday conversion functions.
e_weekday_to_tm_wday() e_weekday_from_tm_wday()
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-misc-utils.c86
-rw-r--r--e-util/e-misc-utils.h2
2 files changed, 88 insertions, 0 deletions
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index 60ebc6bf79..0f350999f5 100644
--- a/e-util/e-misc-utils.c
+++ b/e-util/e-misc-utils.c
@@ -1648,6 +1648,92 @@ e_weekday_get_days_between (GDateWeekday weekday1,
return n_days;
}
+/**
+ * e_weekday_to_tm_wday:
+ * @weekday: a #GDateWeekday
+ *
+ * Converts a #GDateWeekday to the numbering used in
+ * <structname>struct tm</structname>.
+ *
+ * Returns: number of days since Sunday (0 - 6)
+ **/
+gint
+e_weekday_to_tm_wday (GDateWeekday weekday)
+{
+ gint tm_wday;
+
+ switch (weekday) {
+ case G_DATE_MONDAY:
+ tm_wday = 1;
+ break;
+ case G_DATE_TUESDAY:
+ tm_wday = 2;
+ break;
+ case G_DATE_WEDNESDAY:
+ tm_wday = 3;
+ break;
+ case G_DATE_THURSDAY:
+ tm_wday = 4;
+ break;
+ case G_DATE_FRIDAY:
+ tm_wday = 5;
+ break;
+ case G_DATE_SATURDAY:
+ tm_wday = 6;
+ break;
+ case G_DATE_SUNDAY:
+ tm_wday = 0;
+ break;
+ default:
+ g_return_val_if_reached (-1);
+ }
+
+ return tm_wday;
+}
+
+/**
+ * e_weekday_from_tm_wday:
+ * @tm_wday: number of days since Sunday (0 - 6)
+ *
+ * Converts a weekday in the numbering used in
+ * <structname>struct tm</structname> to a #GDateWeekday.
+ *
+ * Returns: a #GDateWeekday
+ **/
+GDateWeekday
+e_weekday_from_tm_wday (gint tm_wday)
+{
+ GDateWeekday weekday;
+
+ switch (tm_wday) {
+ case 0:
+ weekday = G_DATE_SUNDAY;
+ break;
+ case 1:
+ weekday = G_DATE_MONDAY;
+ break;
+ case 2:
+ weekday = G_DATE_TUESDAY;
+ break;
+ case 3:
+ weekday = G_DATE_WEDNESDAY;
+ break;
+ case 4:
+ weekday = G_DATE_THURSDAY;
+ break;
+ case 5:
+ weekday = G_DATE_FRIDAY;
+ break;
+ case 6:
+ weekday = G_DATE_SATURDAY;
+ break;
+ default:
+ g_return_val_if_reached (G_DATE_BAD_WEEKDAY);
+ }
+
+ return weekday;
+}
+
/* 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 20a17b8add..d45f8d34e8 100644
--- a/e-util/e-misc-utils.h
+++ b/e-util/e-misc-utils.h
@@ -147,6 +147,8 @@ GDateWeekday e_weekday_subtract_days (GDateWeekday weekday,
guint n_days);
guint e_weekday_get_days_between (GDateWeekday weekday1,
GDateWeekday weekday2);
+gint e_weekday_to_tm_wday (GDateWeekday weekday);
+GDateWeekday e_weekday_from_tm_wday (gint tm_wday);
gboolean e_file_lock_create (void);
void e_file_lock_destroy (void);