utils: Add macro for computing days after first weekday
Currently, `gcal_date_time_get_start_of_week()` seems to be the only user of this macro function. In the next commit, the month view will use it to traverse weeks while maintaining the weekday. Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/839>
This commit is contained in:
@@ -90,7 +90,7 @@ gcal_date_time_get_start_of_week (GDateTime *date)
|
||||
|
||||
first_weekday = gcal_context_get_week_start_day (context);
|
||||
weekday = g_date_time_get_day_of_week (date) % GCAL_N_WEEKDAYS;
|
||||
n_days_after_week_start = (GCAL_N_WEEKDAYS + weekday - first_weekday) % GCAL_N_WEEKDAYS;
|
||||
n_days_after_week_start = GCAL_NTH_WEEKDAY (weekday, first_weekday);
|
||||
|
||||
start_of_week = g_date_time_add_days (date, -n_days_after_week_start);
|
||||
|
||||
|
||||
@@ -32,6 +32,15 @@
|
||||
#define GCAL_MINUTES_PER_DAY 1440
|
||||
#define GCAL_MAX_MINUTES (GCAL_N_WEEKDAYS * GCAL_MINUTES_PER_DAY)
|
||||
|
||||
/**
|
||||
* GCAL_NTH_WEEKDAY:
|
||||
*
|
||||
* Computes days after the first weekday for use in conjunction
|
||||
* with [struct@GLib.DateTime].
|
||||
*/
|
||||
#define GCAL_NTH_WEEKDAY(weekday, first_weekday) \
|
||||
(weekday - first_weekday + GCAL_N_WEEKDAYS) % GCAL_N_WEEKDAYS
|
||||
|
||||
#define GCAL_DEFAULT_APPLICATION GCAL_APPLICATION (g_application_get_default ())
|
||||
|
||||
#define gcal_clear_timeout(pp) { if (pp && *pp) { g_source_remove (*pp); *pp = 0; } }
|
||||
|
||||
Reference in New Issue
Block a user