#include <iostream>
#include <chrono>
#include <iomanip>
#include <vector>
//using namespace std;
using namespace std::chrono;
void printMonthCalendar(int year_val, int month_val) {
const std::vector<std::string> months = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
// 1. Create a year_month object
year y{year_val};
month m{(unsigned)month_val};
year_month ym{y, m};
// 2. Print Header
std::cout << "\n " << months[month_val - 1] << " " << year_val << "\n";
std::cout << " Sun Mon Tue Wed Thu Fri Sat\n";
// 3. Get first day of the month and its weekday
year_month_day first_day_ymd{y / m / 1};
weekday first_wd{sys_days{first_day_ymd}};
int start_pos = first_wd.c_encoding(); // 0 = Sun, 1 = Mon...
// 4. Get total days in the month using C++20 'last' constant
auto last_day_val = (y / m / last).day();
unsigned total_days = (unsigned)last_day_val;
// 5. Print leading spaces for alignment
for (int i = 0; i < start_pos; i++) std::cout << " ";
// 6. Print days
for (unsigned d = 1; d <= total_days; d++) {
std::cout << std::setw(4) << d;
if ((start_pos + d) % 7 == 0) std::cout << "\n";
}
std::cout << "\n";
}
int main() {
int m = 1, y = 2026;
printMonthCalendar(y, m);
}
/*
run:
January 2026
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
*/