/* Public domain. Like any other piece of software (and information generally), Cal.HC comes with NO WARRANTY. This is version 20231217 of Cal.HC. */ /* Example: #include "Cal.HC" Cal; // print the monthly calendar for the current date Cal(NULL,12); // print the monthly calendar for December of the current year Cal(2000,2); // print the monthly calendar for February 2000 Cal(1865); // print the monthly calendar for the current month for the year 1865; PrintCal(Now); // this is equivalent to Cal(), but it takes a CDate; U8 m; for (m = 1; m < 13; m++) Cal(2022,m); // print a calendar for an entire year */ U0 PrintCal(CDate cdt=Now) { CDateStruct ds; I64 d, end, i; cdt.date = FirstDayOfMon(cdt.date); end = LastDayOfMon(cdt.date); Date2Struct(&ds,cdt); "\n %Z",ds.mon-1,"ST_MONTHS"; " %d\n\n",ds.year; for (i = 0; i < ds.day_of_week; i++) " "; for (d = 0; (d+cdt.date) <= end; i++, d++) { if (30 < d) break; // December bug in LastDayOfMon() if (i == 7) { "\n"; i = 0; } " %2d", 1+d; } "\n\n"; } U0 Cal(I64 year=NULL, U8 month=NULL) { CDate cdt = Now; CDateStruct ds; if (12 < month) { "Cal: FATAL: please enter valid month (1-12)\n"; return; } Date2Struct(&ds,cdt); ds.day_of_mon = 1; if (year) ds.year = year; if (month) ds.mon = month; cdt = Struct2Date(&ds); PrintCal(cdt); }