Skip to content

Commit 489464d

Browse files
dmedrikeszybz
authored andcommitted
calendarspec: add constant for weekdays_bits
1 parent e03234a commit 489464d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/shared/calendarspec.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include "calendarspec.h"
2626

27+
#define BITS_WEEKDAYS 127
28+
2729
static void free_chain(CalendarComponent *c) {
2830
CalendarComponent *n;
2931

@@ -120,7 +122,7 @@ static void fix_year(CalendarComponent *c) {
120122
int calendar_spec_normalize(CalendarSpec *c) {
121123
assert(c);
122124

123-
if (c->weekdays_bits <= 0 || c->weekdays_bits >= 127)
125+
if (c->weekdays_bits <= 0 || c->weekdays_bits >= BITS_WEEKDAYS)
124126
c->weekdays_bits = -1;
125127

126128
fix_year(c->year);
@@ -154,7 +156,7 @@ _pure_ static bool chain_valid(CalendarComponent *c, int from, int to) {
154156
_pure_ bool calendar_spec_valid(CalendarSpec *c) {
155157
assert(c);
156158

157-
if (c->weekdays_bits > 127)
159+
if (c->weekdays_bits > BITS_WEEKDAYS)
158160
return false;
159161

160162
if (!chain_valid(c->year, 1970, 2199))
@@ -194,7 +196,7 @@ static void format_weekdays(FILE *f, const CalendarSpec *c) {
194196

195197
assert(f);
196198
assert(c);
197-
assert(c->weekdays_bits > 0 && c->weekdays_bits <= 127);
199+
assert(c->weekdays_bits > 0 && c->weekdays_bits <= BITS_WEEKDAYS);
198200

199201
for (x = 0, l = -1; x < (int) ELEMENTSOF(days); x++) {
200202

@@ -259,7 +261,7 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) {
259261
if (!f)
260262
return -ENOMEM;
261263

262-
if (c->weekdays_bits > 0 && c->weekdays_bits <= 127) {
264+
if (c->weekdays_bits > 0 && c->weekdays_bits <= BITS_WEEKDAYS) {
263265
format_weekdays(f, c);
264266
fputc(' ', f);
265267
}
@@ -880,7 +882,7 @@ static bool matches_weekday(int weekdays_bits, const struct tm *tm) {
880882
struct tm t;
881883
int k;
882884

883-
if (weekdays_bits < 0 || weekdays_bits >= 127)
885+
if (weekdays_bits < 0 || weekdays_bits >= BITS_WEEKDAYS)
884886
return true;
885887

886888
t = *tm;

0 commit comments

Comments
 (0)