diff -r 60c2588b4455 -r 1040ba37d4c9 src/html.cpp --- a/src/html.cpp Fri Jan 31 22:11:04 2025 +0100 +++ b/src/html.cpp Fri Jan 31 22:27:28 2025 +0100 @@ -26,6 +26,9 @@ #include +#include +namespace chrono = std::chrono; + namespace html { static unsigned indentation; static const char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; @@ -106,15 +109,33 @@ printf("

%s

\n", encode(heading).c_str()); } -void html::table_begin() { +void html::table_begin(int year) { + static constexpr const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + // compute the column spans, first + unsigned colspans[12] = {}; + { + unsigned total_cols = 0; + chrono::sys_days day{chrono::year_month_day{chrono::year{year}, chrono::month{1}, chrono::day{1}}}; + if (chrono::weekday{day}.iso_encoding() != 1) { + colspans[0] = 1; + total_cols = 1; + } + for (unsigned col = 0; col < 12; ++col) { + while (total_cols < html::columns && chrono::year_month_day{day}.month() <= chrono::month{col + 1}) { + ++total_cols; + ++colspans[col]; + day += chrono::days{7}; + } + } + } + + // now render the table heading indent(); puts(""); indent(1); puts(""); indent(1); puts(""); - static constexpr const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - static constexpr int colspans[] = {5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 5}; for (unsigned i = 0 ; i < 12 ; i++) { indent(); printf("\n", colspans[i], months[i]);
%s