Skip to content

Commit

Permalink
Make year output row-major (right then down)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hollasch committed Feb 5, 2024
1 parent d65f080 commit 8fa16f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

//--------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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 << " ";
Expand Down

0 comments on commit 8fa16f1

Please sign in to comment.