From 8fa16f1af2c97f365f0196822f51e3f19da024bc Mon Sep 17 00:00:00 2001 From: Steve Hollasch Date: Mon, 5 Feb 2024 13:21:19 -0800 Subject: [PATCH] Make year output row-major (right then down) The prior version went Jan May Sep Feb Jun Oct Mar Jul Nov Apr Aug Dec Now it displays Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Roughly, top-to-bottom as winter, spring, summer, autumn. I've parameterized this so it can go either way, currently hard-coded to row major. This leaves open a future option to make this a command switch. Resolves #8 Update README --- CHANGELOG.md | 7 +++++++ README.md | 2 +- calendar.cpp | 13 +++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18dd2f2..263b4bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Change Log -- calendar ==================================================================================================== +# v2.0.0 (2024-02-05) + +### Change + - Made the annual calendar print row major. That is, months go left-to-right, then top-to-bottom. + + +---------------------------------------------------------------------------------------------------- # v1.2.0 (2023-12-01) ### Fix diff --git a/README.md b/README.md index 8296f77..a50eda2 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Usage The `--startSun` option sets first day of the week as Sunday. By default, Monday is considered the first day of the week. - calendar 1.2.0 | 2023-12-01 | https://github.com/hollasch/calendar + calendar 2.0.0 | 2024-02-05 | https://github.com/hollasch/calendar Building diff --git a/calendar.cpp b/calendar.cpp index 6886376..f3e5842 100644 --- a/calendar.cpp +++ b/calendar.cpp @@ -18,7 +18,7 @@ using std::cout, std::cerr; -const char* version = "calendar 1.2.0 | 2023-12-01 | https://github.com/hollasch/calendar"; +const char* version = "calendar 2.0.0 | 2024-02-05 | https://github.com/hollasch/calendar"; //-------------------------------------------------------------------------------------------------- @@ -190,7 +190,12 @@ void printYear (const ProgramParameters& params) { // Print four rows of three month columns. - for (int leftMonth=0; leftMonth < 4; ++leftMonth) { + const bool rowMajor = true; // Months go (true=left-to-right, false=top-to-bottom) first. + const int lastRowStart = rowMajor ? 9 : 3; + const int rowStep = rowMajor ? 3 : 1; + const int colStep = rowMajor ? 1 : 4; + + for (int leftMonth=0; leftMonth <= lastRowStart; leftMonth += rowStep) { cout << "\n " << params.dowHeader // Print day-of-week headers << " " << params.dowHeader @@ -204,7 +209,7 @@ void printYear (const ProgramParameters& params) { // Initialize start and last days for each month column. for (int column = 0; column < 3; ++column) { - int month = leftMonth + 4*column; + int month = leftMonth + colStep*column; day[column] = monthWeekStartDay(params.startSun, monthDayOneDOW(params.year, month)), lastDay[column] = monthNumDays(params.year, month); } @@ -214,7 +219,7 @@ void printYear (const ProgramParameters& params) { while (day[0] <= lastDay[0] || day[1] <= lastDay[1] || day[2] <= lastDay[2]) { cout << '\n'; for (int column = 0; column < 3; ++column) { - int month = leftMonth + 4*column; + int month = leftMonth + colStep*column; if (0 < column) cout << " ";