+typedef BOOL NGMonthSet[12];
+typedef BOOL NGMonthDaySet[31];
+
+static void NGMonthDaySet_clear(NGMonthDaySet *daySet) {
+ register unsigned i;
+
+ for (i = 0; i < 31; i++)
+ (*daySet)[i] = NO;
+}
+
+static void NGMonthDaySet_copyOrUnion(NGMonthDaySet *base, NGMonthDaySet *new,
+ BOOL doCopy)
+{
+ register unsigned i;
+
+ if (doCopy)
+ memcpy(base, new, sizeof(NGMonthDaySet));
+ else {
+ for (i = 0; i < 31; i++) {
+ if (!(*new)[i])
+ (*base)[i] = NO;
+ }
+ }
+}
+
+static void NGMonthDaySet_fillWithByMonthDay(NGMonthDaySet *daySet,
+ NSArray *byMonthDay,
+ int numDaysInMonth)
+{
+ /* list of days in the month */
+ unsigned i, count;
+
+ NGMonthDaySet_clear(daySet);
+
+ for (i = 0, count = [byMonthDay count]; i < count; i++) {
+ int dayInMonth; /* -31..-1 and 1..31 */
+
+ if ((dayInMonth = [[byMonthDay objectAtIndex:i] intValue]) == 0)
+ continue; /* invalid value */
+ if (dayInMonth > numDaysInMonth)
+ continue; /* this month has less days */
+ if (dayInMonth < -numDaysInMonth)
+ continue; /* this month has less days */
+
+ /* adjust negative days */
+
+ if (dayInMonth < 0) {
+ /* eg: -1 == last day in month, 30 days => 30 */
+ dayInMonth = 32 - dayInMonth /* because we count from 1 */;
+ }
+
+ (*daySet)[dayInMonth] = YES;
+ }
+}
+
+static void NGMonthDaySet_fillWithByDayX(NGMonthDaySet *daySet,
+ unsigned dayMask,
+ int occurrence1)
+{
+ unsigned i, count;
+
+ NGMonthDaySet_clear(daySet);
+ // TODO: complete me
+}
+