mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
cal: Display month names
For now let's use them from AK/DateConstants.h, in accordance with the FIXME those propably should be provided by the locale.
This commit is contained in:
parent
79f5fb798a
commit
1d47d5bb8b
Notes:
sideshowbarker
2024-07-16 22:54:10 +09:00
Author: https://github.com/karolba Commit: https://github.com/SerenityOS/serenity/commit/1d47d5bb8b Pull-request: https://github.com/SerenityOS/serenity/pull/17707 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/kleinesfilmroellchen Reviewed-by: https://github.com/linusg
2 changed files with 60 additions and 44 deletions
|
@ -22,17 +22,17 @@ Days, months and years are specified with numbers. Week starts at Sunday.
|
||||||
```sh
|
```sh
|
||||||
# Display the current month
|
# Display the current month
|
||||||
$ cal
|
$ cal
|
||||||
12 - 1992
|
March - 2023
|
||||||
Su Mo Tu We Th Fr Sa
|
Su Mo Tu We Th Fr Sa
|
||||||
1 2 3
|
1 2 3 4
|
||||||
4 5 6 7 8 9 10
|
5 6 7 8 9 10 11
|
||||||
11 12 13 14 15 16 17*
|
12 13 14 15 16 17 18
|
||||||
18 19 20 21 22 23 24
|
19 20 21 22 23 24 25
|
||||||
25 26 27 28 29 30 31
|
26 27 28 29 30 31
|
||||||
|
|
||||||
# Display any month
|
# Display any month
|
||||||
$ cal 03 2019
|
$ cal 1 1999
|
||||||
03 - 2019
|
January - 1999
|
||||||
Su Mo Tu We Th Fr Sa
|
Su Mo Tu We Th Fr Sa
|
||||||
1 2
|
1 2
|
||||||
3 4 5 6 7 8 9
|
3 4 5 6 7 8 9
|
||||||
|
@ -41,40 +41,45 @@ Su Mo Tu We Th Fr Sa
|
||||||
24 25 26 27 28 29 30
|
24 25 26 27 28 29 30
|
||||||
31
|
31
|
||||||
|
|
||||||
# Display an entire year
|
$ cal 2023
|
||||||
$ cal 2000
|
Year 2023
|
||||||
Year 2000
|
|
||||||
|
|
||||||
|
January - 2023 February - 2023 March - 2023
|
||||||
|
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
||||||
|
1 2 3 4 5 6 7 1 2 3 4 1 2 3 4
|
||||||
|
8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11
|
||||||
|
15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18
|
||||||
|
22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25
|
||||||
|
29 30 31 26 27 28 26 27 28 29 30 31
|
||||||
|
|
||||||
|
|
||||||
|
April - 2023 May - 2023 June - 2023
|
||||||
|
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
||||||
|
1 1 2 3 4 5 6 1 2 3
|
||||||
|
2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10
|
||||||
|
9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17
|
||||||
|
16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24
|
||||||
|
23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30
|
||||||
|
30
|
||||||
|
|
||||||
|
|
||||||
|
July - 2023 August - 2023 September - 2023
|
||||||
|
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
||||||
|
1 1 2 3 4 5 1 2
|
||||||
|
2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9
|
||||||
|
9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16
|
||||||
|
16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23
|
||||||
|
23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30
|
||||||
|
30 31
|
||||||
|
|
||||||
|
|
||||||
|
October - 2023 November - 2023 December - 2023
|
||||||
|
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
||||||
|
1 2 3 4 5 6 7 1 2 3 4 1 2
|
||||||
|
8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
|
||||||
|
15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
|
||||||
|
22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
|
||||||
|
29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
|
||||||
|
|
||||||
01 - 2000 02 - 2000 03 - 2000
|
|
||||||
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
|
||||||
1 1 2 3 4 5 1 2 3 4
|
|
||||||
2 3 4 5 6 7 8 6 7 8 9 10 11 12 5 6 7 8 9 10 11
|
|
||||||
9 10 11 12 13 14 15 13 14 15 16 17 18 19 12 13 14 15 16 17 18
|
|
||||||
16 17 18 19 20 21 22 20 21 22 23 24 25 26 19 20 21 22 23 24 25
|
|
||||||
23 24 25 26 27 28 29 27 28 29 26 27 28 29 30 31
|
|
||||||
30 31
|
|
||||||
04 - 2000 05 - 2000 06 - 2000
|
|
||||||
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
|
||||||
1 1 2 3 4 5 6 1 2 3
|
|
||||||
2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10
|
|
||||||
9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17
|
|
||||||
16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24
|
|
||||||
23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30
|
|
||||||
30
|
|
||||||
07 - 2000 08 - 2000 09 - 2000
|
|
||||||
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
|
||||||
1 1 2 3 4 5 1 2
|
|
||||||
2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9
|
|
||||||
9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16
|
|
||||||
16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23
|
|
||||||
23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30
|
|
||||||
30 31
|
|
||||||
10 - 2000 11 - 2000 12 - 2000
|
|
||||||
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
|
||||||
1 2 3 4 5 6 7 1 2 3 4 1 2
|
|
||||||
8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
|
|
||||||
15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
|
|
||||||
22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
|
|
||||||
29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
|
|
||||||
31
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/DateConstants.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
@ -26,12 +27,22 @@ int current_year;
|
||||||
int current_month;
|
int current_month;
|
||||||
int current_day;
|
int current_day;
|
||||||
|
|
||||||
|
static ErrorOr<StringView> month_name(int month)
|
||||||
|
{
|
||||||
|
int month_index = month - 1;
|
||||||
|
|
||||||
|
if (month_index < 0 || month_index >= static_cast<int>(AK::long_month_names.size()))
|
||||||
|
return Error::from_string_view("Month out of range"sv);
|
||||||
|
|
||||||
|
return AK::long_month_names.at(month_index);
|
||||||
|
}
|
||||||
|
|
||||||
static ErrorOr<Vector<String>> month_lines_to_print(int month, int year)
|
static ErrorOr<Vector<String>> month_lines_to_print(int month, int year)
|
||||||
{
|
{
|
||||||
Vector<String> lines;
|
Vector<String> lines;
|
||||||
|
|
||||||
// FIXME: Both the month name and month header text should be provided by a locale
|
// FIXME: Both the month name and month header text should be provided by a locale
|
||||||
TRY(lines.try_append(TRY(String::formatted("{: ^{}s}", TRY(String::formatted("{:02} - {:02}", month, year)), month_width))));
|
TRY(lines.try_append(TRY(String::formatted("{: ^{}s}", TRY(String::formatted("{} - {}", TRY(month_name(month)), year)), month_width))));
|
||||||
TRY(lines.try_append(TRY(String::from_utf8("Su Mo Tu We Th Fr Sa"sv))));
|
TRY(lines.try_append(TRY(String::from_utf8("Su Mo Tu We Th Fr Sa"sv))));
|
||||||
|
|
||||||
int day_to_print = 1;
|
int day_to_print = 1;
|
||||||
|
|
Loading…
Reference in a new issue