mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
cal: Don't accept passing a [day]
Every other cal implementation just highlights the current day instead of letting you specify a custom one to highlight. It doesn't seem to be that useful, and is currently broken - no day gets highlighted at all, because the `target_day` global is never written to. Moreover, this complicates parsing the arguments. This commit also fixes parsing a case where just a year is provided to `cal` - for example `cal 2023`.
This commit is contained in:
parent
f5cb46e316
commit
b57c718418
2 changed files with 8 additions and 11 deletions
|
@ -5,12 +5,13 @@ cal - Display a calendar
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
```**sh
|
```**sh
|
||||||
$ cal [[[day] month] year]
|
$ cal [[month] year]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
This program displays a simple calendar. If no arguments are specified, the current month is displayed with the current day highlighted.
|
This program displays a simple calendar. If no arguments are specified, the current month is displayed with the current day highlighted.
|
||||||
|
An overview of a whole year is displayed when a `year` is passed without a `month`.
|
||||||
|
|
||||||
Days, months and years are specified with numbers. Week starts at Sunday.
|
Days, months and years are specified with numbers. Week starts at Sunday.
|
||||||
|
|
||||||
|
|
|
@ -94,14 +94,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
TRY(Core::System::unveil("/etc/timezone", "r"));
|
TRY(Core::System::unveil("/etc/timezone", "r"));
|
||||||
TRY(Core::System::unveil(nullptr, nullptr));
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
|
|
||||||
int day = 0;
|
|
||||||
int month = 0;
|
int month = 0;
|
||||||
int year = 0;
|
int year = 0;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.set_general_help("Display a nice overview of a month or year, defaulting to the current month.");
|
args_parser.set_general_help("Display a nice overview of a month or year, defaulting to the current month.");
|
||||||
// FIXME: This should ensure two values get parsed as month + year
|
// FIXME: This should ensure one value gets parsed as just a year
|
||||||
args_parser.add_positional_argument(day, "Day of year", "day", Core::ArgsParser::Required::No);
|
|
||||||
args_parser.add_positional_argument(month, "Month", "month", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(month, "Month", "month", Core::ArgsParser::Required::No);
|
||||||
args_parser.add_positional_argument(year, "Year", "year", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(year, "Year", "year", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
@ -109,22 +107,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
auto* tm = localtime(&now);
|
auto* tm = localtime(&now);
|
||||||
|
|
||||||
// Hack: workaround two values parsing as day + month.
|
// Hack: workaround one value parsing as a month
|
||||||
if (day && month && !year) {
|
if (month && !year) {
|
||||||
year = month;
|
year = month;
|
||||||
month = day;
|
month = 0;
|
||||||
day = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool year_mode = !day && !month && year;
|
bool year_mode = !month && year;
|
||||||
|
|
||||||
if (!year)
|
if (!year)
|
||||||
year = tm->tm_year + 1900;
|
year = tm->tm_year + 1900;
|
||||||
if (!month)
|
if (!month)
|
||||||
month = tm->tm_mon + 1;
|
month = tm->tm_mon + 1;
|
||||||
if (!day)
|
|
||||||
day = tm->tm_mday;
|
|
||||||
|
|
||||||
|
// FIXME: Those are really _target_ year and month values - not current ones
|
||||||
current_year = year;
|
current_year = year;
|
||||||
current_month = month;
|
current_month = month;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue