utils: Turn number of weekdays into a macro

While "7" may be obvious in the context of calendaring that
it represents the number of week days, it often gives me the
impression of it being a magic number when I'm hyperfocused on certain
parts of the codebase for several consecutive hours. Turning the
number into a macro helps me scan functions much more easily.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/674>
This commit is contained in:
Hari Rana
2026-03-08 21:53:40 -04:00
parent da7b625e18
commit 50e048c7e0
14 changed files with 109 additions and 107 deletions
+2 -2
View File
@@ -84,8 +84,8 @@ gcal_date_time_get_start_of_week (GDateTime *date)
g_assert (date != NULL);
first_weekday = get_first_weekday ();
weekday = g_date_time_get_day_of_week (date) % 7;
n_days_after_week_start = (7 + weekday - first_weekday) % 7;
weekday = g_date_time_get_day_of_week (date) % N_WEEKDAYS;
n_days_after_week_start = (N_WEEKDAYS + weekday - first_weekday) % N_WEEKDAYS;
start_of_week = g_date_time_add_days (date, -n_days_after_week_start);
+5 -5
View File
@@ -50,7 +50,7 @@
*/
static const gint
ab_day[7] =
ab_day[N_WEEKDAYS] =
{
ABDAY_1,
ABDAY_2,
@@ -402,7 +402,7 @@ get_first_weekday (void)
else
g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n");
week_start = (week_1stday + first_weekday - 1) % 7;
week_start = (week_1stday + first_weekday - 1) % N_WEEKDAYS;
#else
@@ -418,7 +418,7 @@ get_first_weekday (void)
else
week_start = -1;
if (week_start < 0 || week_start > 6)
if (week_start < 0 || week_start > N_WEEKDAYS - 1)
{
g_warning ("Whoever translated calendar:week_start:0 for GTK+ "
"did so wrongly.\n");
@@ -771,7 +771,7 @@ get_alarm_trigger_minutes (GcalEvent *event,
alarm_dt = g_date_time_add_full (gcal_event_get_date_start (event),
0,
0,
- (i_cal_duration_get_days (duration) + i_cal_duration_get_weeks (duration) * 7),
- (i_cal_duration_get_days (duration) + i_cal_duration_get_weeks (duration) * N_WEEKDAYS),
- i_cal_duration_get_hours (duration),
- i_cal_duration_get_minutes (duration),
- i_cal_duration_get_seconds (duration));
@@ -903,7 +903,7 @@ is_workday (guint day)
gchar territory[3] = { 0, };
guint i;
if (day > 6)
if (day > N_WEEKDAYS - 1)
return FALSE;
no_work_days = GCAL_WEEK_DAY_SATURDAY | GCAL_WEEK_DAY_SUNDAY;
+2 -1
View File
@@ -26,9 +26,10 @@
#include <libecal/libecal.h>
#include <libgweather/gweather.h>
#define N_WEEKDAYS 7
#define ALIGNED(x) (round (x) + 0.5)
#define MINUTES_PER_DAY 1440
#define MAX_MINUTES (7 * MINUTES_PER_DAY)
#define MAX_MINUTES (N_WEEKDAYS * MINUTES_PER_DAY)
#define gcal_clear_timeout(pp) { if (pp && *pp) { g_source_remove (*pp); *pp = 0; } }
#define gcal_clear_signal_handler(pp,instance) { if (pp && *pp > 0) { g_signal_handler_disconnect (instance, *pp); *pp = 0; } }