Index: stable/12/usr.bin/calendar/calendars/calendar.usholiday =================================================================== --- stable/12/usr.bin/calendar/calendars/calendar.usholiday (revision 359781) +++ stable/12/usr.bin/calendar/calendars/calendar.usholiday (revision 359782) @@ -1,42 +1,41 @@ /* * USA holiday * * $FreeBSD$ */ #ifndef _calendar_usholiday_ #define _calendar_usholiday_ 01/01 New Year's Day 01/14 Julian Calendar New Year's Day 02/02 Groundhog Day 02/14 St. Valentine's Day 02/MonThird President's Day (3rd Monday of February) 03/05 Mother-in-Law Day, USA 03/SunSecond Daylight Savings Time begins in USA; clocks move forward (2nd Sunday of March) 03/17 St. Patrick's Day 03/20* Vernal Equinox 04/01 April Fool's Day 04/15 Income Tax Day, USA. 04/28* Arbor Day, USA (varies from state to state) 05/SunSecond Mother's Day (2nd Sunday of May) 05/SatThird Armed Forces in USA Day (3rd Saturday of May) 05/MonLast Memorial Day in USA (Last Monday of May) 06/SunThird Father's Day (3rd Sunday of June) 06/21* Summer Solstice 07/04 US Independence Day 09/MonFirst Labor Day in USA (1st Monday of September) 09/SunSecond Grandparent's Day in USA (2nd Sunday of September; varies from state to state) 09/22* Autumnal Equinox 10/MonSecond Columbus Day in USA (2nd Monday of October) 10/31 All Hallows Eve (Halloween) -11/05* Election Day in USA (1st Tuesday after 1st Monday for even years) 11/SunFirst Daylight Savings Time ends in USA; clocks move back (1st Sunday of November) 11/11 Veterans' Day 11/ThuFourth Thanksgiving Day (4th Thursday in November) 12/21* Winter Solstice 12/24 Christmas Eve 12/25 Christmas 12/31 New Year's Eve #endif /* !_calendar_usholiday_ */ Index: stable/12/usr.bin/calendar/parsedata.c =================================================================== --- stable/12/usr.bin/calendar/parsedata.c (revision 359781) +++ stable/12/usr.bin/calendar/parsedata.c (revision 359782) @@ -1,1118 +1,1124 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 1992-2009 Edwin Groothuis . * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "calendar.h" static char *showflags(int flags); static int isonlydigits(char *s, int nostar); static const char *getmonthname(int i); static int checkmonth(char *s, size_t *len, size_t *offset, const char **month); static const char *getdayofweekname(int i); static int checkdayofweek(char *s, size_t *len, size_t *offset, const char **dow); static int indextooffset(char *s); static int parseoffset(char *s); static char *floattoday(int year, double f); static char *floattotime(double f); static int wdayom (int day, int offset, int month, int year); /* * Expected styles: * * Date ::= Month . ' ' . DayOfMonth | * Month . ' ' . DayOfWeek . ModifierIndex | * Month . '/' . DayOfMonth | * Month . '/' . DayOfWeek . ModifierIndex | * DayOfMonth . ' ' . Month | * DayOfMonth . '/' . Month | * DayOfWeek . ModifierIndex . ' ' .Month | * DayOfWeek . ModifierIndex . '/' .Month | * DayOfWeek . ModifierIndex | * SpecialDay . ModifierOffset * * Month ::= MonthName | MonthNumber | '*' * MonthNumber ::= '0' ... '9' | '00' ... '09' | '10' ... '12' * MonthName ::= MonthNameShort | MonthNameLong * MonthNameLong ::= 'January' ... 'December' * MonthNameShort ::= 'Jan' ... 'Dec' | 'Jan.' ... 'Dec.' * * DayOfWeek ::= DayOfWeekShort | DayOfWeekLong * DayOfWeekShort ::= 'Mon' .. 'Sun' * DayOfWeekLong ::= 'Monday' .. 'Sunday' * DayOfMonth ::= '0' ... '9' | '00' ... '09' | '10' ... '29' | * '30' ... '31' | '*' * * ModifierOffset ::= '' | '+' . ModifierNumber | '-' . ModifierNumber * ModifierNumber ::= '0' ... '9' | '00' ... '99' | '000' ... '299' | * '300' ... '359' | '360' ... '365' * ModifierIndex ::= 'Second' | 'Third' | 'Fourth' | 'Fifth' | * 'First' | 'Last' * * SpecialDay ::= 'Easter' | 'Paskha' | 'ChineseNewYear' * */ static int determinestyle(char *date, int *flags, char *month, int *imonth, char *dayofmonth, int *idayofmonth, char *dayofweek, int *idayofweek, char *modifieroffset, char *modifierindex, char *specialday, char *year, int *iyear) { char *p, *p1, *p2, *py; const char *dow, *pmonth; char pold; size_t len, offset; *flags = F_NONE; *month = '\0'; *imonth = 0; *year = '\0'; *iyear = 0; *dayofmonth = '\0'; *idayofmonth = 0; *dayofweek = '\0'; *idayofweek = 0; *modifieroffset = '\0'; *modifierindex = '\0'; *specialday = '\0'; #define CHECKSPECIAL(s1, s2, lens2, type) \ if (s2 != NULL && strncmp(s1, s2, lens2) == 0) { \ *flags |= F_SPECIALDAY; \ *flags |= type; \ *flags |= F_VARIABLE; \ if (strlen(s1) == lens2) { \ strcpy(specialday, s1); \ return (1); \ } \ strncpy(specialday, s1, lens2); \ specialday[lens2] = '\0'; \ strcpy(modifieroffset, s1 + lens2); \ *flags |= F_MODIFIEROFFSET; \ return (1); \ } if ((p = strchr(date, ' ')) == NULL) { if ((p = strchr(date, '/')) == NULL) { CHECKSPECIAL(date, STRING_CNY, strlen(STRING_CNY), F_CNY); CHECKSPECIAL(date, ncny.name, ncny.len, F_CNY); CHECKSPECIAL(date, STRING_NEWMOON, strlen(STRING_NEWMOON), F_NEWMOON); CHECKSPECIAL(date, nnewmoon.name, nnewmoon.len, F_NEWMOON); CHECKSPECIAL(date, STRING_FULLMOON, strlen(STRING_FULLMOON), F_FULLMOON); CHECKSPECIAL(date, nfullmoon.name, nfullmoon.len, F_FULLMOON); CHECKSPECIAL(date, STRING_PASKHA, strlen(STRING_PASKHA), F_PASKHA); CHECKSPECIAL(date, npaskha.name, npaskha.len, F_PASKHA); CHECKSPECIAL(date, STRING_EASTER, strlen(STRING_EASTER), F_EASTER); CHECKSPECIAL(date, neaster.name, neaster.len, F_EASTER); CHECKSPECIAL(date, STRING_MAREQUINOX, strlen(STRING_MAREQUINOX), F_MAREQUINOX); CHECKSPECIAL(date, nmarequinox.name, nmarequinox.len, F_SEPEQUINOX); CHECKSPECIAL(date, STRING_SEPEQUINOX, strlen(STRING_SEPEQUINOX), F_SEPEQUINOX); CHECKSPECIAL(date, nsepequinox.name, nsepequinox.len, F_SEPEQUINOX); CHECKSPECIAL(date, STRING_JUNSOLSTICE, strlen(STRING_JUNSOLSTICE), F_JUNSOLSTICE); CHECKSPECIAL(date, njunsolstice.name, njunsolstice.len, F_JUNSOLSTICE); CHECKSPECIAL(date, STRING_DECSOLSTICE, strlen(STRING_DECSOLSTICE), F_DECSOLSTICE); CHECKSPECIAL(date, ndecsolstice.name, ndecsolstice.len, F_DECSOLSTICE); if (checkdayofweek(date, &len, &offset, &dow) != 0) { *flags |= F_DAYOFWEEK; *flags |= F_VARIABLE; *idayofweek = offset; if (strlen(date) == len) { strcpy(dayofweek, date); return (1); } strncpy(dayofweek, date, len); dayofweek[len] = '\0'; strcpy(modifierindex, date + len); *flags |= F_MODIFIERINDEX; return (1); } if (isonlydigits(date, 1)) { /* Assume month number only */ *flags |= F_MONTH; *imonth = (int)strtol(date, (char **)NULL, 10); strcpy(month, getmonthname(*imonth)); return(1); } return (0); } } /* * After this, leave by goto-ing to "allfine" or "fail" to restore the * original data in `date'. */ pold = *p; *p = 0; p1 = date; p2 = p + 1; /* Now p2 points to the next field and p1 to the first field */ if ((py = strchr(p2, '/')) != NULL) { /* We have a year in the string. Now this is getting tricky */ strcpy(year, p1); *iyear = (int)strtol(year, NULL, 10); p1 = p2; p2 = py + 1; *py = 0; *flags |= F_YEAR; } /* Check if there is a month-string in the date */ if ((checkmonth(p1, &len, &offset, &pmonth) != 0) || (checkmonth(p2, &len, &offset, &pmonth) != 0 && (p2 = p1))) { /* p2 is the non-month part */ *flags |= F_MONTH; *imonth = offset; strcpy(month, getmonthname(offset)); if (isonlydigits(p2, 1)) { strcpy(dayofmonth, p2); *idayofmonth = (int)strtol(p2, (char **)NULL, 10); *flags |= F_DAYOFMONTH; goto allfine; } if (strcmp(p2, "*") == 0) { *flags |= F_ALLDAY; goto allfine; } if (checkdayofweek(p2, &len, &offset, &dow) != 0) { *flags |= F_DAYOFWEEK; *flags |= F_VARIABLE; *idayofweek = offset; strcpy(dayofweek, getdayofweekname(offset)); if (strlen(p2) == len) goto allfine; strcpy(modifierindex, p2 + len); *flags |= F_MODIFIERINDEX; goto allfine; } goto fail; } /* Check if there is an every-day or every-month in the string */ if ((strcmp(p1, "*") == 0 && isonlydigits(p2, 1)) || (strcmp(p2, "*") == 0 && isonlydigits(p1, 1) && (p2 = p1))) { int d; *flags |= F_ALLMONTH; *flags |= F_DAYOFMONTH; d = (int)strtol(p2, (char **)NULL, 10); *idayofmonth = d; sprintf(dayofmonth, "%d", d); goto allfine; } /* Month as a number, then a weekday */ if (isonlydigits(p1, 1) && checkdayofweek(p2, &len, &offset, &dow) != 0) { int d; *flags |= F_MONTH; *flags |= F_DAYOFWEEK; *flags |= F_VARIABLE; *idayofweek = offset; d = (int)strtol(p1, (char **)NULL, 10); *imonth = d; strcpy(month, getmonthname(d)); strcpy(dayofweek, getdayofweekname(offset)); if (strlen(p2) == len) goto allfine; strcpy(modifierindex, p2 + len); *flags |= F_MODIFIERINDEX; goto allfine; } /* If both the month and date are specified as numbers */ if (isonlydigits(p1, 1) && isonlydigits(p2, 0)) { /* Now who wants to be this ambiguous? :-( */ int m, d; if (strchr(p2, '*') != NULL) *flags |= F_VARIABLE; m = (int)strtol(p1, (char **)NULL, 10); d = (int)strtol(p2, (char **)NULL, 10); *flags |= F_MONTH; *flags |= F_DAYOFMONTH; if (m > 12) { *imonth = d; *idayofmonth = m; strcpy(month, getmonthname(d)); sprintf(dayofmonth, "%d", m); } else { *imonth = m; *idayofmonth = d; strcpy(month, getmonthname(m)); sprintf(dayofmonth, "%d", d); } goto allfine; } /* FALLTHROUGH */ fail: *p = pold; return (0); allfine: *p = pold; return (1); } void remember(int *rememberindex, int *y, int *m, int *d, char **ed, int yy, int mm, int dd, char *extra); void remember(int *rememberindex, int *y, int *m, int *d, char **ed, int yy, int mm, int dd, char *extra) { static int warned = 0; if (*rememberindex >= MAXCOUNT - 1) { if (warned == 0) warnx("Index > %d, ignored", MAXCOUNT); warned++; return; } y[*rememberindex] = yy; m[*rememberindex] = mm; d[*rememberindex] = dd; if (extra != NULL) strcpy(ed[*rememberindex], extra); else ed[*rememberindex][0] = '\0'; *rememberindex += 1; } static void debug_determinestyle(int dateonly, char *date, int flags, char *month, int imonth, char *dayofmonth, int idayofmonth, char *dayofweek, int idayofweek, char *modifieroffset, char *modifierindex, char *specialday, char *year, int iyear) { if (dateonly != 0) { printf("-------\ndate: |%s|\n", date); if (dateonly == 1) return; } printf("flags: %x - %s\n", flags, showflags(flags)); if (modifieroffset[0] != '\0') printf("modifieroffset: |%s|\n", modifieroffset); if (modifierindex[0] != '\0') printf("modifierindex: |%s|\n", modifierindex); if (year[0] != '\0') printf("year: |%s| (%d)\n", year, iyear); if (month[0] != '\0') printf("month: |%s| (%d)\n", month, imonth); if (dayofmonth[0] != '\0') printf("dayofmonth: |%s| (%d)\n", dayofmonth, idayofmonth); if (dayofweek[0] != '\0') printf("dayofweek: |%s| (%d)\n", dayofweek, idayofweek); if (specialday[0] != '\0') printf("specialday: |%s|\n", specialday); } static struct yearinfo { int year; int ieaster, ipaskha, firstcnyday; double ffullmoon[MAXMOONS], fnewmoon[MAXMOONS]; double ffullmooncny[MAXMOONS], fnewmooncny[MAXMOONS]; int ichinesemonths[MAXMOONS]; double equinoxdays[2], solsticedays[2]; int *monthdays; struct yearinfo *next; } *years, *yearinfo; /* * Calculate dates with offset from weekdays, like Thurs-3, Wed+2, etc. * day is the day of the week, * offset the ordinal number of the weekday in the month. */ static int wdayom (int day, int offset, int month, int year) { /* Weekday of first day in month */ int wday1; /* first day of month */ /* Weekday of last day in month */ int wdayn; int d; wday1 = first_dayofweek_of_month(year, month); if (wday1 < 0) /* not set */ return (wday1); /* * Date of zeroth or first of our weekday in month, depending on the * relationship with the first of the month. The range is -6:6. */ d = (day - wday1 + 1) % 7; /* * Which way are we counting? Offset 0 is invalid, abs (offset) > 5 is * meaningless, but that's OK. Offset 5 may or may not be meaningless, * so there's no point in complaining for complaining's sake. */ if (offset < 0) { /* back from end of month */ /* FIXME */ wdayn = d; while (wdayn <= yearinfo->monthdays[month]) wdayn += 7; d = offset * 7 + wdayn; } else if (offset > 0){ if (d > 0) d += offset * 7 - 7; else d += offset * 7; } else warnx ("Invalid offset 0"); return (d); } /* * Possible date formats include any combination of: * 3-charmonth (January, Jan, Jan) * 3-charweekday (Friday, Monday, mon.) * numeric month or day (1, 2, 04) * * Any character may separate them, or they may not be separated. Any line, * following a line that is matched, that starts with "whitespace", is shown * along with the matched line. */ int parsedaymonth(char *date, int *yearp, int *monthp, int *dayp, int *flags, char **edp) { char month[100], dayofmonth[100], dayofweek[100], modifieroffset[100]; char syear[100]; char modifierindex[100], specialday[100]; int idayofweek = -1, imonth = -1, idayofmonth = -1, iyear = -1; int year, remindex; int d, m, dow, rm, rd, offset; char *ed; int retvalsign = 1; /* * CONVENTION * * Month: 1-12 * Monthname: Jan .. Dec * Day: 1-31 * Weekday: Mon .. Sun * */ *flags = 0; if (debug) debug_determinestyle(1, date, *flags, month, imonth, dayofmonth, idayofmonth, dayofweek, idayofweek, modifieroffset, modifierindex, specialday, syear, iyear); if (determinestyle(date, flags, month, &imonth, dayofmonth, &idayofmonth, dayofweek, &idayofweek, modifieroffset, modifierindex, specialday, syear, &iyear) == 0) { if (debug) printf("Failed!\n"); return (0); } if (debug) debug_determinestyle(0, date, *flags, month, imonth, dayofmonth, idayofmonth, dayofweek, idayofweek, modifieroffset, modifierindex, specialday, syear, iyear); remindex = 0; for (year = year1; year <= year2; year++) { int lflags = *flags; /* If the year is specified, only do it if it is this year! */ if ((lflags & F_YEAR) != 0) if (iyear != year) continue; lflags &= ~F_YEAR; /* Get important dates for this year */ yearinfo = years; while (yearinfo != NULL) { if (yearinfo->year == year) break; yearinfo = yearinfo -> next; } if (yearinfo == NULL) { yearinfo = (struct yearinfo *)calloc(1, sizeof(struct yearinfo)); if (yearinfo == NULL) errx(1, "Unable to allocate more years"); yearinfo->year = year; yearinfo->next = years; years = yearinfo; yearinfo->monthdays = monthdaytab[isleap(year)]; yearinfo->ieaster = easter(year); yearinfo->ipaskha = paskha(year); fpom(year, UTCOffset, yearinfo->ffullmoon, yearinfo->fnewmoon); fpom(year, UTCOFFSET_CNY, yearinfo->ffullmooncny, yearinfo->fnewmooncny); fequinoxsolstice(year, UTCOffset, yearinfo->equinoxdays, yearinfo->solsticedays); /* * CNY: Match day with sun longitude at 330` with new * moon */ yearinfo->firstcnyday = calculatesunlongitude30(year, UTCOFFSET_CNY, yearinfo->ichinesemonths); for (m = 0; yearinfo->fnewmooncny[m] >= 0; m++) { if (yearinfo->fnewmooncny[m] > yearinfo->firstcnyday) { yearinfo->firstcnyday = floor(yearinfo->fnewmooncny[m - 1]); break; } } } /* Same day every year */ if (lflags == (F_MONTH | F_DAYOFMONTH)) { if (!remember_ymd(year, imonth, idayofmonth)) continue; remember(&remindex, yearp, monthp, dayp, edp, year, imonth, idayofmonth, NULL); continue; } /* XXX Same day every year, but variable */ if (lflags == (F_MONTH | F_DAYOFMONTH | F_VARIABLE)) { if (!remember_ymd(year, imonth, idayofmonth)) continue; remember(&remindex, yearp, monthp, dayp, edp, year, imonth, idayofmonth, NULL); continue; } /* Same day every month */ if (lflags == (F_ALLMONTH | F_DAYOFMONTH)) { for (m = 1; m <= 12; m++) { if (!remember_ymd(year, m, idayofmonth)) continue; remember(&remindex, yearp, monthp, dayp, edp, year, m, idayofmonth, NULL); } continue; } /* Every day of a month */ if (lflags == (F_ALLDAY | F_MONTH)) { for (d = 1; d <= yearinfo->monthdays[imonth]; d++) { if (!remember_ymd(year, imonth, d)) continue; remember(&remindex, yearp, monthp, dayp, edp, year, imonth, d, NULL); } continue; } /* One day of every month */ if (lflags == (F_ALLMONTH | F_DAYOFWEEK)) { for (m = 1; m <= 12; m++) { if (!remember_ymd(year, m, idayofmonth)) continue; remember(&remindex, yearp, monthp, dayp, edp, year, m, idayofmonth, NULL); } continue; } /* Every dayofweek of the year */ if (lflags == (F_DAYOFWEEK | F_VARIABLE)) { dow = first_dayofweek_of_year(year); - d = (idayofweek - dow + 8) % 7; + if (dow < 0) + continue; + d = (idayofweek - dow + 7) % 7 + 1; while (d <= 366) { if (remember_yd(year, d, &rm, &rd)) remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, NULL); d += 7; } continue; } /* * Every so-manied dayofweek of every month of the year: * Thu-3 */ if (lflags == (F_DAYOFWEEK | F_MODIFIERINDEX | F_VARIABLE)) { offset = indextooffset(modifierindex); for (m = 0; m <= 12; m++) { d = wdayom (idayofweek, offset, m, year); if (remember_ymd(year, m, d)) { remember(&remindex, yearp, monthp, dayp, edp, year, m, d, NULL); continue; } } continue; } /* * A certain dayofweek of a month * Jan/Thu-3 */ if (lflags == (F_MONTH | F_DAYOFWEEK | F_MODIFIERINDEX | F_VARIABLE)) { offset = indextooffset(modifierindex); dow = first_dayofweek_of_month(year, imonth); - d = (idayofweek - dow + 8) % 7; + if (dow < 0) + continue; + d = (idayofweek - dow + 7) % 7 + 1; if (offset > 0) { while (d <= yearinfo->monthdays[imonth]) { if (--offset == 0 && remember_ymd(year, imonth, d)) { remember(&remindex, yearp, monthp, dayp, edp, year, imonth, d, NULL); continue; } d += 7; } continue; } if (offset < 0) { while (d <= yearinfo->monthdays[imonth]) d += 7; while (offset != 0) { offset++; d -= 7; } if (remember_ymd(year, imonth, d)) remember(&remindex, yearp, monthp, dayp, edp, year, imonth, d, NULL); continue; } continue; } /* Every dayofweek of the month */ if (lflags == (F_DAYOFWEEK | F_MONTH | F_VARIABLE)) { dow = first_dayofweek_of_month(year, imonth); - d = (idayofweek - dow + 8) % 7; + if (dow < 0) + continue; + d = (idayofweek - dow + 7) % 7 + 1; while (d <= yearinfo->monthdays[imonth]) { if (remember_ymd(year, imonth, d)) remember(&remindex, yearp, monthp, dayp, edp, year, imonth, d, NULL); d += 7; } continue; } /* Easter */ if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_EASTER)) { offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); if (remember_yd(year, yearinfo->ieaster + offset, &rm, &rd)) remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, NULL); continue; } /* Paskha */ if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_PASKHA)) { offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); if (remember_yd(year, yearinfo->ipaskha + offset, &rm, &rd)) remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, NULL); continue; } /* Chinese New Year */ if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_CNY)) { offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); if (remember_yd(year, yearinfo->firstcnyday + offset, &rm, &rd)) remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, NULL); continue; } /* FullMoon */ if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_FULLMOON)) { int i; offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); for (i = 0; yearinfo->ffullmoon[i] > 0; i++) { if (remember_yd(year, floor(yearinfo->ffullmoon[i]) + offset, &rm, &rd)) { ed = floattotime( yearinfo->ffullmoon[i]); remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, ed); } } continue; } /* NewMoon */ if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_NEWMOON)) { int i; offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); for (i = 0; yearinfo->ffullmoon[i] > 0; i++) { if (remember_yd(year, floor(yearinfo->fnewmoon[i]) + offset, &rm, &rd)) { ed = floattotime(yearinfo->fnewmoon[i]); remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, ed); } } continue; } /* (Mar|Sep)Equinox */ if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_MAREQUINOX)) { offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); if (remember_yd(year, yearinfo->equinoxdays[0] + offset, &rm, &rd)) { ed = floattotime(yearinfo->equinoxdays[0]); remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, ed); } continue; } if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_SEPEQUINOX)) { offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); if (remember_yd(year, yearinfo->equinoxdays[1] + offset, &rm, &rd)) { ed = floattotime(yearinfo->equinoxdays[1]); remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, ed); } continue; } /* (Jun|Dec)Solstice */ if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_JUNSOLSTICE)) { offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); if (remember_yd(year, yearinfo->solsticedays[0] + offset, &rm, &rd)) { ed = floattotime(yearinfo->solsticedays[0]); remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, ed); } continue; } if ((lflags & ~F_MODIFIEROFFSET) == (F_SPECIALDAY | F_VARIABLE | F_DECSOLSTICE)) { offset = 0; if ((lflags & F_MODIFIEROFFSET) != 0) offset = parseoffset(modifieroffset); if (remember_yd(year, yearinfo->solsticedays[1] + offset, &rm, &rd)) { ed = floattotime(yearinfo->solsticedays[1]); remember(&remindex, yearp, monthp, dayp, edp, year, rm, rd, ed); } continue; } if (debug) { printf("Unprocessed:\n"); debug_determinestyle(2, date, lflags, month, imonth, dayofmonth, idayofmonth, dayofweek, idayofweek, modifieroffset, modifierindex, specialday, syear, iyear); } retvalsign = -1; } if (retvalsign == -1) return (-remindex - 1); else return (remindex); } static char * showflags(int flags) { static char s[1000]; s[0] = '\0'; if ((flags & F_YEAR) != 0) strcat(s, "year "); if ((flags & F_MONTH) != 0) strcat(s, "month "); if ((flags & F_DAYOFWEEK) != 0) strcat(s, "dayofweek "); if ((flags & F_DAYOFMONTH) != 0) strcat(s, "dayofmonth "); if ((flags & F_MODIFIERINDEX) != 0) strcat(s, "modifierindex "); if ((flags & F_MODIFIEROFFSET) != 0) strcat(s, "modifieroffset "); if ((flags & F_SPECIALDAY) != 0) strcat(s, "specialday "); if ((flags & F_ALLMONTH) != 0) strcat(s, "allmonth "); if ((flags & F_ALLDAY) != 0) strcat(s, "allday "); if ((flags & F_VARIABLE) != 0) strcat(s, "variable "); if ((flags & F_CNY) != 0) strcat(s, "chinesenewyear "); if ((flags & F_PASKHA) != 0) strcat(s, "paskha "); if ((flags & F_EASTER) != 0) strcat(s, "easter "); if ((flags & F_FULLMOON) != 0) strcat(s, "fullmoon "); if ((flags & F_NEWMOON) != 0) strcat(s, "newmoon "); if ((flags & F_MAREQUINOX) != 0) strcat(s, "marequinox "); if ((flags & F_SEPEQUINOX) != 0) strcat(s, "sepequinox "); if ((flags & F_JUNSOLSTICE) != 0) strcat(s, "junsolstice "); if ((flags & F_DECSOLSTICE) != 0) strcat(s, "decsolstice "); return s; } static const char * getmonthname(int i) { if (i <= 0 || i > 12) return (""); if (nmonths[i - 1].len != 0 && nmonths[i - 1].name != NULL) return (nmonths[i - 1].name); return (months[i - 1]); } static int checkmonth(char *s, size_t *len, size_t *offset, const char **month) { struct fixs *n; int i; for (i = 0; fnmonths[i].name != NULL; i++) { n = fnmonths + i; if (strncasecmp(s, n->name, n->len) == 0) { *len = n->len; *month = n->name; *offset = i + 1; return (1); } } for (i = 0; nmonths[i].name != NULL; i++) { n = nmonths + i; if (strncasecmp(s, n->name, n->len) == 0) { *len = n->len; *month = n->name; *offset = i + 1; return (1); } } for (i = 0; fmonths[i] != NULL; i++) { *len = strlen(fmonths[i]); if (strncasecmp(s, fmonths[i], *len) == 0) { *month = fmonths[i]; *offset = i + 1; return (1); } } for (i = 0; months[i] != NULL; i++) { if (strncasecmp(s, months[i], 3) == 0) { *len = 3; *month = months[i]; *offset = i + 1; return (1); } } return (0); } static const char * getdayofweekname(int i) { if (ndays[i].len != 0 && ndays[i].name != NULL) return (ndays[i].name); return (days[i]); } static int checkdayofweek(char *s, size_t *len, size_t *offset, const char **dow) { struct fixs *n; int i; for (i = 0; fndays[i].name != NULL; i++) { n = fndays + i; if (strncasecmp(s, n->name, n->len) == 0) { *len = n->len; *dow = n->name; *offset = i; return (1); } } for (i = 0; ndays[i].name != NULL; i++) { n = ndays + i; if (strncasecmp(s, n->name, n->len) == 0) { *len = n->len; *dow = n->name; *offset = i; return (1); } } for (i = 0; fdays[i] != NULL; i++) { *len = strlen(fdays[i]); if (strncasecmp(s, fdays[i], *len) == 0) { *dow = fdays[i]; *offset = i; return (1); } } for (i = 0; days[i] != NULL; i++) { if (strncasecmp(s, days[i], 3) == 0) { *len = 3; *dow = days[i]; *offset = i; return (1); } } return (0); } static int isonlydigits(char *s, int nostar) { int i; for (i = 0; s[i] != '\0'; i++) { if (nostar == 0 && s[i] == '*' && s[i + 1] == '\0') return 1; if (!isdigit((unsigned char)s[i])) return (0); } return (1); } static int indextooffset(char *s) { int i; struct fixs *n; char *es; if (s[0] == '+' || s[0] == '-') { i = strtol (s, &es, 10); if (*es != '\0') /* trailing junk */ errx (1, "Invalid specifier format: %s\n", s); return (i); } for (i = 0; i < 6; i++) { if (strcasecmp(s, sequences[i]) == 0) { if (i == 5) return (-1); return (i + 1); } } for (i = 0; i < 6; i++) { n = nsequences + i; if (n->len == 0) continue; if (strncasecmp(s, n->name, n->len) == 0) { if (i == 5) return (-1); return (i + 1); } } return (0); } static int parseoffset(char *s) { return strtol(s, NULL, 10); } static char * floattotime(double f) { static char buf[100]; int hh, mm, ss, i; f -= floor(f); i = f * SECSPERDAY; hh = i / SECSPERHOUR; i %= SECSPERHOUR; mm = i / SECSPERMINUTE; i %= SECSPERMINUTE; ss = i; sprintf(buf, "%02d:%02d:%02d", hh, mm, ss); return (buf); } static char * floattoday(int year, double f) { static char buf[100]; int i, m, d, hh, mm, ss; int *cumdays = cumdaytab[isleap(year)]; for (i = 0; 1 + cumdays[i] < f; i++) ; m = --i; d = floor(f - 1 - cumdays[i]); f -= floor(f); i = f * SECSPERDAY; hh = i / SECSPERHOUR; i %= SECSPERHOUR; mm = i / SECSPERMINUTE; i %= SECSPERMINUTE; ss = i; sprintf(buf, "%02d-%02d %02d:%02d:%02d", m, d, hh, mm, ss); return (buf); } void dodebug(char *what) { int year; printf("UTCOffset: %g\n", UTCOffset); printf("eastlongitude: %d\n", EastLongitude); if (strcmp(what, "moon") == 0) { double ffullmoon[MAXMOONS], fnewmoon[MAXMOONS]; int i; for (year = year1; year <= year2; year++) { fpom(year, UTCOffset, ffullmoon, fnewmoon); printf("Full moon %d:\t", year); for (i = 0; ffullmoon[i] >= 0; i++) { printf("%g (%s) ", ffullmoon[i], floattoday(year, ffullmoon[i])); } printf("\nNew moon %d:\t", year); for (i = 0; fnewmoon[i] >= 0; i++) { printf("%g (%s) ", fnewmoon[i], floattoday(year, fnewmoon[i])); } printf("\n"); } return; } if (strcmp(what, "sun") == 0) { double equinoxdays[2], solsticedays[2]; for (year = year1; year <= year2; year++) { printf("Sun in %d:\n", year); fequinoxsolstice(year, UTCOffset, equinoxdays, solsticedays); printf("e[0] - %g (%s)\n", equinoxdays[0], floattoday(year, equinoxdays[0])); printf("e[1] - %g (%s)\n", equinoxdays[1], floattoday(year, equinoxdays[1])); printf("s[0] - %g (%s)\n", solsticedays[0], floattoday(year, solsticedays[0])); printf("s[1] - %g (%s)\n", solsticedays[1], floattoday(year, solsticedays[1])); } return; } } Index: stable/12/usr.bin/calendar/tests/calendar.calibrate =================================================================== --- stable/12/usr.bin/calendar/tests/calendar.calibrate (revision 359781) +++ stable/12/usr.bin/calendar/tests/calendar.calibrate (revision 359782) @@ -1,374 +1,375 @@ /* * Calibration calendar for calendar(1) * * $FreeBSD$ */ LANG=C 01/01 jan 1 01/02 jan 2 01/03 jan 3 01/04 jan 4 01/05 jan 5 01/06 jan 6 01/07 jan 7 01/08 jan 8 01/09 jan 9 01/10 jan 10 01/11 jan 11 01/12 jan 12 01/13 jan 13 01/14 jan 14 01/15 jan 15 01/16 jan 16 01/17 jan 17 01/18 jan 18 01/19 jan 19 01/20 jan 20 01/21 jan 21 01/22 jan 22 01/23 jan 23 01/24 jan 24 01/25 jan 25 01/26 jan 26 01/27 jan 27 01/28 jan 28 01/29 jan 29 01/30 jan 30 01/31 jan 31 02/01 feb 1 02/02 feb 2 02/03 feb 3 02/04 feb 4 02/05 feb 5 02/06 feb 6 02/07 feb 7 02/08 feb 8 02/09 feb 9 02/10 feb 10 02/11 feb 11 02/12 feb 12 02/13 feb 13 02/14 feb 14 02/15 feb 15 02/16 feb 16 02/17 feb 17 02/18 feb 18 02/19 feb 19 02/20 feb 20 02/21 feb 21 02/22 feb 22 02/23 feb 23 02/24 feb 24 02/25 feb 25 02/26 feb 26 02/27 feb 27 02/28 feb 28 02/29 feb 29 03/01 mar 1 03/02 mar 2 03/03 mar 3 03/04 mar 4 03/05 mar 5 03/06 mar 6 03/07 mar 7 03/08 mar 8 03/09 mar 9 03/10 mar 10 03/11 mar 11 03/12 mar 12 03/13 mar 13 03/14 mar 14 03/15 mar 15 03/16 mar 16 03/17 mar 17 03/18 mar 18 03/19 mar 19 03/20 mar 20 03/21 mar 21 03/22 mar 22 03/23 mar 23 03/24 mar 24 03/25 mar 25 03/26 mar 26 03/27 mar 27 03/28 mar 28 03/29 mar 29 03/30 mar 30 03/31 mar 31 04/01 apr 1 04/02 apr 2 04/03 apr 3 04/04 apr 4 04/05 apr 5 04/06 apr 6 04/07 apr 7 04/08 apr 8 04/09 apr 9 04/10 apr 10 04/11 apr 11 04/12 apr 12 04/13 apr 13 04/14 apr 14 04/15 apr 15 04/16 apr 16 04/17 apr 17 04/18 apr 18 04/19 apr 19 04/20 apr 20 04/21 apr 21 04/22 apr 22 04/23 apr 23 04/24 apr 24 04/25 apr 25 04/26 apr 26 04/27 apr 27 04/28 apr 28 04/29 apr 29 04/30 apr 30 05/01 may 1 05/02 may 2 05/03 may 3 05/04 may 4 05/05 may 5 05/06 may 6 05/07 may 7 05/08 may 8 05/09 may 9 05/10 may 10 05/11 may 11 05/12 may 12 05/13 may 13 05/14 may 14 05/15 may 15 05/16 may 16 05/17 may 17 05/18 may 18 05/19 may 19 05/20 may 20 05/21 may 21 05/22 may 22 05/23 may 23 05/24 may 24 05/25 may 25 05/26 may 26 05/27 may 27 05/28 may 28 05/29 may 29 05/30 may 30 05/31 may 31 06/01 jun 1 06/02 jun 2 06/03 jun 3 06/04 jun 4 06/05 jun 5 06/06 jun 6 06/07 jun 7 06/08 jun 8 06/09 jun 9 06/10 jun 10 06/11 jun 11 06/12 jun 12 06/13 jun 13 06/14 jun 14 06/15 jun 15 06/16 jun 16 06/17 jun 17 06/18 jun 18 06/19 jun 19 06/20 jun 20 06/21 jun 21 06/22 jun 22 06/23 jun 23 06/24 jun 24 06/25 jun 25 06/26 jun 26 06/27 jun 27 06/28 jun 28 06/29 jun 29 06/30 jun 30 +06/SunThird sunthird 07/01 jul 1 07/02 jul 2 07/03 jul 3 07/04 jul 4 07/05 jul 5 07/06 jul 6 07/07 jul 7 07/08 jul 8 07/09 jul 9 07/10 jul 10 07/11 jul 11 07/12 jul 12 07/13 jul 13 07/14 jul 14 07/15 jul 15 07/16 jul 16 07/17 jul 17 07/18 jul 18 07/19 jul 19 07/20 jul 20 07/21 jul 21 07/22 jul 22 07/23 jul 23 07/24 jul 24 07/25 jul 25 07/26 jul 26 07/27 jul 27 07/28 jul 28 07/29 jul 29 07/30 jul 30 07/31 jul 31 08/01 aug 1 08/02 aug 2 08/03 aug 3 08/04 aug 4 08/05 aug 5 08/06 aug 6 08/07 aug 7 08/08 aug 8 08/09 aug 9 08/10 aug 10 08/11 aug 11 08/12 aug 12 08/13 aug 13 08/14 aug 14 08/15 aug 15 08/16 aug 16 08/17 aug 17 08/18 aug 18 08/19 aug 19 08/20 aug 20 08/21 aug 21 08/22 aug 22 08/23 aug 23 08/24 aug 24 08/25 aug 25 08/26 aug 26 08/27 aug 27 08/28 aug 28 08/29 aug 29 08/30 aug 30 08/31 aug 31 09/01 sep 1 09/02 sep 2 09/03 sep 3 09/04 sep 4 09/05 sep 5 09/06 sep 6 09/07 sep 7 09/08 sep 8 09/09 sep 9 09/10 sep 10 09/11 sep 11 09/12 sep 12 09/13 sep 13 09/14 sep 14 09/15 sep 15 09/16 sep 16 09/17 sep 17 09/18 sep 18 09/19 sep 19 09/20 sep 20 09/21 sep 21 09/22 sep 22 09/23 sep 23 09/24 sep 24 09/25 sep 25 09/26 sep 26 09/27 sep 27 09/28 sep 28 09/29 sep 29 09/30 sep 30 10/01 oct 1 10/02 oct 2 10/03 oct 3 10/04 oct 4 10/05 oct 5 10/06 oct 6 10/07 oct 7 10/08 oct 8 10/09 oct 9 10/10 oct 10 10/11 oct 11 10/12 oct 12 10/13 oct 13 10/14 oct 14 10/15 oct 15 10/16 oct 16 10/17 oct 17 10/18 oct 18 10/19 oct 19 10/20 oct 20 10/21 oct 21 10/22 oct 22 10/23 oct 23 10/24 oct 24 10/25 oct 25 10/26 oct 26 10/27 oct 27 10/28 oct 28 10/29 oct 29 10/30 oct 30 10/31 oct 31 11/01 nov 1 11/02 nov 2 11/03 nov 3 11/04 nov 4 11/05 nov 5 11/06 nov 6 11/07 nov 7 11/08 nov 8 11/09 nov 9 11/10 nov 10 11/11 nov 11 11/12 nov 12 11/13 nov 13 11/14 nov 14 11/15 nov 15 11/16 nov 16 11/17 nov 17 11/18 nov 18 11/19 nov 19 11/20 nov 20 11/21 nov 21 11/22 nov 22 11/23 nov 23 11/24 nov 24 11/25 nov 25 11/26 nov 26 11/27 nov 27 11/28 nov 28 11/29 nov 29 11/30 nov 30 12/01 dec 1 12/02 dec 2 12/03 dec 3 12/04 dec 4 12/05 dec 5 12/06 dec 6 12/07 dec 7 12/08 dec 8 12/09 dec 9 12/10 dec 10 12/11 dec 11 12/12 dec 12 12/13 dec 13 12/14 dec 14 12/15 dec 15 12/16 dec 16 12/17 dec 17 12/18 dec 18 12/19 dec 19 12/20 dec 20 12/21 dec 21 12/22 dec 22 12/23 dec 23 12/24 dec 24 12/25 dec 25 12/26 dec 26 12/27 dec 27 12/28 dec 28 12/29 dec 29 12/30 dec 30 12/31 dec 31 Index: stable/12/usr.bin/calendar/tests/regress.s5.out =================================================================== --- stable/12/usr.bin/calendar/tests/regress.s5.out (nonexistent) +++ stable/12/usr.bin/calendar/tests/regress.s5.out (revision 359782) @@ -0,0 +1,3 @@ +Jun 21* sunthird +Jun 21 jun 21 +Jun 22 jun 22 Property changes on: stable/12/usr.bin/calendar/tests/regress.s5.out ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +y \ No newline at end of property Index: stable/12/usr.bin/calendar/tests/regress.sh =================================================================== --- stable/12/usr.bin/calendar/tests/regress.sh (revision 359781) +++ stable/12/usr.bin/calendar/tests/regress.sh (revision 359782) @@ -1,45 +1,46 @@ # $FreeBSD$ CALENDAR_FILE="-f ${SRCDIR}/calendar.calibrate" CALENDAR_BIN="calendar" CALENDAR="${CALENDAR_BIN} ${CALENDAR_FILE}" REGRESSION_START($1) -echo 1..28 +echo 1..29 REGRESSION_TEST(`s1',`$CALENDAR -t 29.12.2006') REGRESSION_TEST(`s2',`$CALENDAR -t 30.12.2006') REGRESSION_TEST(`s3',`$CALENDAR -t 31.12.2006') REGRESSION_TEST(`s4',`$CALENDAR -t 01.01.2007') +REGRESSION_TEST(`s5',`$CALENDAR -t 21.06.2015') REGRESSION_TEST(`a1',`$CALENDAR -A 3 -t 28.12.2006') REGRESSION_TEST(`a2',`$CALENDAR -A 3 -t 29.12.2006') REGRESSION_TEST(`a3',`$CALENDAR -A 3 -t 30.12.2006') REGRESSION_TEST(`a4',`$CALENDAR -A 3 -t 31.12.2006') REGRESSION_TEST(`a5',`$CALENDAR -A 3 -t 01.01.2007') REGRESSION_TEST(`b1',`$CALENDAR -B 3 -t 31.12.2006') REGRESSION_TEST(`b2',`$CALENDAR -B 3 -t 01.01.2007') REGRESSION_TEST(`b3',`$CALENDAR -B 3 -t 02.01.2007') REGRESSION_TEST(`b4',`$CALENDAR -B 3 -t 03.01.2007') REGRESSION_TEST(`b5',`$CALENDAR -B 3 -t 04.01.2007') REGRESSION_TEST(`w0-1',`$CALENDAR -W 0 -t 28.12.2006') REGRESSION_TEST(`w0-2',`$CALENDAR -W 0 -t 29.12.2006') REGRESSION_TEST(`w0-3',`$CALENDAR -W 0 -t 30.12.2006') REGRESSION_TEST(`w0-4',`$CALENDAR -W 0 -t 31.12.2006') REGRESSION_TEST(`w0-5',`$CALENDAR -W 0 -t 01.01.2007') REGRESSION_TEST(`w0-6',`$CALENDAR -W 0 -t 02.01.2007') REGRESSION_TEST(`w0-7',`$CALENDAR -W 0 -t 03.01.2007') REGRESSION_TEST(`wn-1',`$CALENDAR -W 0 -t 28.12.2006') REGRESSION_TEST(`wn-2',`$CALENDAR -W 1 -t 28.12.2006') REGRESSION_TEST(`wn-3',`$CALENDAR -W 2 -t 28.12.2006') REGRESSION_TEST(`wn-4',`$CALENDAR -W 3 -t 28.12.2006') REGRESSION_TEST(`wn-5',`$CALENDAR -W 4 -t 28.12.2006') REGRESSION_TEST(`wn-6',`$CALENDAR -W 5 -t 28.12.2006') REGRESSION_TEST(`wn-7',`$CALENDAR -W 6 -t 28.12.2006') REGRESSION_END() Index: stable/12 =================================================================== --- stable/12 (revision 359781) +++ stable/12 (revision 359782) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r359585,359587