* cal(1) year formatting
@ 2016-05-18 12:51 Karel Zak
2016-05-18 13:05 ` Pádraig Brady
0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2016-05-18 12:51 UTC (permalink / raw)
To: util-linux
See the patch below. I have no strong opinion about it, any
objection?
Karel
>From e671a62ef8574b16cd6acbfd04dc35c514b184e5 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Wed, 18 May 2016 14:43:20 +0200
Subject: [PATCH] cal: use %04d for year
It seems that people are crazy enough to assume that "cal 16" is the
year 2016, rather than 16 (2000 years ago).
This patch makes it more clear as the output is 0016.
Addresses: https://github.com/karelzak/util-linux/issues/320
Signed-off-by: Karel Zak <kzak@redhat.com>
---
misc-utils/cal.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 2a53b89..3e20530 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -516,7 +516,7 @@ static void headers_init(struct cal_control *ctl)
char tmp[FMT_ST_CHARS];
int year_len;
- year_len = snprintf(tmp, sizeof(tmp), "%d", ctl->req.year);
+ year_len = snprintf(tmp, sizeof(tmp), "%04d", ctl->req.year);
if (year_len < 0 || (size_t)year_len >= sizeof(tmp)) {
/* XXX impossible error */
@@ -612,13 +612,13 @@ static void cal_output_header(struct cal_month *month, const struct cal_control
if (!ctl->header_year) {
my_putstring("\n");
for (i = month; i; i = i->next) {
- sprintf(out, _("%d"), i->year);
+ sprintf(out, _("%04d"), i->year);
center(out, ctl->week_width - 1, i->next == NULL ? 0 : ctl->gutter_width);
}
}
} else {
for (i = month; i; i = i->next) {
- sprintf(out, _("%s %d"), ctl->full_month[i->month - 1], i->year);
+ sprintf(out, _("%s %04d"), ctl->full_month[i->month - 1], i->year);
center(out, ctl->week_width - 1, i->next == NULL ? 0 : ctl->gutter_width);
}
}
@@ -762,7 +762,7 @@ static void yearly(const struct cal_control *ctl)
year_width--;
if (ctl->header_year) {
- sprintf(out, "%d", ctl->req.year);
+ sprintf(out, "%04d", ctl->req.year);
center(out, year_width, 0);
my_putstring("\n\n");
}
--
2.4.11
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: cal(1) year formatting
2016-05-18 12:51 cal(1) year formatting Karel Zak
@ 2016-05-18 13:05 ` Pádraig Brady
2016-05-18 20:09 ` Sami Kerola
0 siblings, 1 reply; 3+ messages in thread
From: Pádraig Brady @ 2016-05-18 13:05 UTC (permalink / raw)
To: Karel Zak, util-linux
On 18/05/16 13:51, Karel Zak wrote:
>
> See the patch below. I have no strong opinion about it, any
> objection?
>
> Karel
>
>
>>From e671a62ef8574b16cd6acbfd04dc35c514b184e5 Mon Sep 17 00:00:00 2001
> From: Karel Zak <kzak@redhat.com>
> Date: Wed, 18 May 2016 14:43:20 +0200
> Subject: [PATCH] cal: use %04d for year
>
> It seems that people are crazy enough to assume that "cal 16" is the
> year 2016, rather than 16 (2000 years ago).
>
> This patch makes it more clear as the output is 0016.
>
> Addresses: https://github.com/karelzak/util-linux/issues/320
> Signed-off-by: Karel Zak <kzak@redhat.com>
> ---
> misc-utils/cal.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/misc-utils/cal.c b/misc-utils/cal.c
> index 2a53b89..3e20530 100644
> --- a/misc-utils/cal.c
> +++ b/misc-utils/cal.c
> @@ -516,7 +516,7 @@ static void headers_init(struct cal_control *ctl)
> char tmp[FMT_ST_CHARS];
> int year_len;
>
> - year_len = snprintf(tmp, sizeof(tmp), "%d", ctl->req.year);
> + year_len = snprintf(tmp, sizeof(tmp), "%04d", ctl->req.year);
>
> if (year_len < 0 || (size_t)year_len >= sizeof(tmp)) {
> /* XXX impossible error */
> @@ -612,13 +612,13 @@ static void cal_output_header(struct cal_month *month, const struct cal_control
> if (!ctl->header_year) {
> my_putstring("\n");
> for (i = month; i; i = i->next) {
> - sprintf(out, _("%d"), i->year);
> + sprintf(out, _("%04d"), i->year);
> center(out, ctl->week_width - 1, i->next == NULL ? 0 : ctl->gutter_width);
> }
> }
> } else {
> for (i = month; i; i = i->next) {
> - sprintf(out, _("%s %d"), ctl->full_month[i->month - 1], i->year);
> + sprintf(out, _("%s %04d"), ctl->full_month[i->month - 1], i->year);
> center(out, ctl->week_width - 1, i->next == NULL ? 0 : ctl->gutter_width);
> }
> }
> @@ -762,7 +762,7 @@ static void yearly(const struct cal_control *ctl)
> year_width--;
>
> if (ctl->header_year) {
> - sprintf(out, "%d", ctl->req.year);
> + sprintf(out, "%04d", ctl->req.year);
> center(out, year_width, 0);
> my_putstring("\n\n");
> }
>
more upsides than downsides so +1 from me
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: cal(1) year formatting
2016-05-18 13:05 ` Pádraig Brady
@ 2016-05-18 20:09 ` Sami Kerola
0 siblings, 0 replies; 3+ messages in thread
From: Sami Kerola @ 2016-05-18 20:09 UTC (permalink / raw)
To: Pádraig Brady; +Cc: Karel Zak, util-linux
On 18 May 2016 at 14:05, P=C3=A1draig Brady <P@draigbrady.com> wrote:
> On 18/05/16 13:51, Karel Zak wrote:
>>
>>
>> See the patch below. I have no strong opinion about it, any
>> objection?
>>
>> Karel
>>
>>
>>> From e671a62ef8574b16cd6acbfd04dc35c514b184e5 Mon Sep 17 00:00:00 2001
>>
>> From: Karel Zak <kzak@redhat.com>
>> Date: Wed, 18 May 2016 14:43:20 +0200
>> Subject: [PATCH] cal: use %04d for year
>>
>> It seems that people are crazy enough to assume that "cal 16" is the
>> year 2016, rather than 16 (2000 years ago).
>>
>> This patch makes it more clear as the output is 0016.
>>
>> Addresses: https://github.com/karelzak/util-linux/issues/320
>> Signed-off-by: Karel Zak <kzak@redhat.com>
>> ---
>> misc-utils/cal.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/misc-utils/cal.c b/misc-utils/cal.c
>> index 2a53b89..3e20530 100644
>> --- a/misc-utils/cal.c
>> +++ b/misc-utils/cal.c
>> @@ -516,7 +516,7 @@ static void headers_init(struct cal_control *ctl)
>> char tmp[FMT_ST_CHARS];
>> int year_len;
>>
>> - year_len =3D snprintf(tmp, sizeof(tmp), "%d", ctl->req.year);
>> + year_len =3D snprintf(tmp, sizeof(tmp), "%04d", ctl->req.year);
>>
>> if (year_len < 0 || (size_t)year_len >=3D sizeof(tmp)) {
>> /* XXX impossible error */
>> @@ -612,13 +612,13 @@ static void cal_output_header(struct cal_month
>> *month, const struct cal_control
>> if (!ctl->header_year) {
>> my_putstring("\n");
>> for (i =3D month; i; i =3D i->next) {
>> - sprintf(out, _("%d"), i->year);
>> + sprintf(out, _("%04d"), i->year);
>> center(out, ctl->week_width - 1, i->next
>> =3D=3D NULL ? 0 : ctl->gutter_width);
>> }
>> }
>> } else {
>> for (i =3D month; i; i =3D i->next) {
>> - sprintf(out, _("%s %d"), ctl->full_month[i->mont=
h
>> - 1], i->year);
>> + sprintf(out, _("%s %04d"),
>> ctl->full_month[i->month - 1], i->year);
>> center(out, ctl->week_width - 1, i->next =3D=3D =
NULL ?
>> 0 : ctl->gutter_width);
>> }
>> }
>> @@ -762,7 +762,7 @@ static void yearly(const struct cal_control *ctl)
>> year_width--;
>>
>> if (ctl->header_year) {
>> - sprintf(out, "%d", ctl->req.year);
>> + sprintf(out, "%04d", ctl->req.year);
>> center(out, year_width, 0);
>> my_putstring("\n\n");
>> }
>>
>
> more upsides than downsides so +1 from me
A little bit surprising that this sort of emphasis of past is needed,
but what is needed is needed. +1
--=20
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-18 20:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-18 12:51 cal(1) year formatting Karel Zak
2016-05-18 13:05 ` Pádraig Brady
2016-05-18 20:09 ` Sami Kerola
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.