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
+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;