diff options
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-misc-utils.c | 65 | ||||
-rw-r--r-- | e-util/e-misc-utils.h | 6 |
2 files changed, 71 insertions, 0 deletions
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c index 261612c87b..60ebc6bf79 100644 --- a/e-util/e-misc-utils.c +++ b/e-util/e-misc-utils.c @@ -1583,6 +1583,71 @@ e_weekday_get_prev (GDateWeekday weekday) return prev; } +/** + * e_weekday_add_days: + * @weekday: a #GDateWeekday + * @n_days: number of days to add + * + * Increments @weekday by @n_days. + * + * Returns: a #GDateWeekday + **/ +GDateWeekday +e_weekday_add_days (GDateWeekday weekday, + guint n_days) +{ + n_days %= 7; /* Weekdays repeat every 7 days. */ + + while (n_days-- > 0) + weekday = e_weekday_get_next (weekday); + + return weekday; +} + +/** + * e_weekday_subtract_days: + * @weekday: a #GDateWeekday + * @n_days: number of days to subtract + * + * Decrements @weekday by @n_days. + * + * Returns: a #GDateWeekday + **/ +GDateWeekday +e_weekday_subtract_days (GDateWeekday weekday, + guint n_days) +{ + n_days %= 7; /* Weekdays repeat every 7 days. */ + + while (n_days-- > 0) + weekday = e_weekday_get_prev (weekday); + + return weekday; +} + +/** + * e_weekday_get_days_between: + * @weekday1: a #GDateWeekday + * @weekday2: a #GDateWeekday + * + * Counts the number of days starting at @weekday1 and ending at @weekday2. + * + * Returns: the number of days + **/ +guint +e_weekday_get_days_between (GDateWeekday weekday1, + GDateWeekday weekday2) +{ + guint n_days = 0; + + while (weekday1 != weekday2) { + n_days++; + weekday1 = e_weekday_get_next (weekday1); + } + + return n_days; +} + /* 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 282b1fda04..20a17b8add 100644 --- a/e-util/e-misc-utils.h +++ b/e-util/e-misc-utils.h @@ -141,6 +141,12 @@ const gchar * e_get_weekday_name (GDateWeekday weekday, gboolean abbreviated); GDateWeekday e_weekday_get_next (GDateWeekday weekday); GDateWeekday e_weekday_get_prev (GDateWeekday weekday); +GDateWeekday e_weekday_add_days (GDateWeekday weekday, + guint n_days); +GDateWeekday e_weekday_subtract_days (GDateWeekday weekday, + guint n_days); +guint e_weekday_get_days_between (GDateWeekday weekday1, + GDateWeekday weekday2); gboolean e_file_lock_create (void); void e_file_lock_destroy (void); |