bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] gawk with dates before 1970


From: Aharon Robbins
Subject: Re: [bug-gawk] gawk with dates before 1970
Date: Mon, 13 Apr 2015 16:30:03 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Hi.

Thanks for the question and report.

> From: Glaudiston Gomes da Silva <address@hidden>
> Date: Thu, 9 Apr 2015 15:25:33 -0300
> To: address@hidden
> Subject: Re: [bug-gawk] gawk with dates before 1970
> Content-Type: text/plain; charset=UTF-8
>
> I wrote the post asking for help in stackoverflow:
> http://stackoverflow.com/questions/29542459/awk-with-dates-before-1970
>
> The context is that I need to format/manipulate dates before 1970. mktime
> seems to be fine, but strftime do not accept negative numbers.
>
> For all others on stackoverflow post (and for me) it's seems to be a bug in
> gawk.
>
> glaudiston:/sources/gawk-4.1.1c$ ./gawk 'BEGIN{t=mktime("1960 01 01 00 00
> 00"); print t; print strftime("%Y-%m-%d", t) }'
> -315608400
> gawk: cmd. line:1: fatal: strftime: second argument less than 0 or too big
> for time_t
>
> So I looked in source file and commented out the 2 lines that test if is
> negative and make it fatal.
> 1701,1702c1701,1702
> glaudiston:/sources/gawk-4.1.1c$ diff builtin.c.orig builtin.c
> 1916,1917c1916,1917
> <                       if (clock_val < 0)
> <                               fatal(_("strftime: second argument less
> than 0 or too big for time_t"));
> ---
> >                       //if (clock_val < 0)
> >                       //      fatal(_("strftime: second argument less
> than 0 or too big for time_t"));
>
> And it worked like magic:
> glaudiston:/sources/gawk-4.1.1c$ ./gawk 'BEGIN{t=mktime("1960 01 01 00 00
> 00"); print t; print strftime("%Y-%m-%d", t) }'
> -315608400
> 1960-01-01
>
> 3 questions:
> 1) Why do exists this 2 lines?

The check is there because once upon a time, many systems could not handle
dates before 1970.  I believe that as far as formal standards are concerned,
time_t values are not defined to be able to handle such values.

> 2) Can my change break anything else?

I don't think so.

> 3) If is not a dangerous change, there is any reason to do not add this to
> the next main release code ?

I think you're right and it's OK to allow negative values. I
have removed those two lines and pushed the change into the git
repo, so the next release will allow negative values.

> Date: Fri, 10 Apr 2015 10:31:31 +0300
> From: Eli Zaretskii <address@hidden>
> To: Glaudiston Gomes da Silva <address@hidden>
> Cc: address@hidden
> Subject: Re: [bug-gawk] gawk with dates before 1970
>
> You cannot just delete those lines, because some systems have time_t
> as an unsigned data type.

The actual variable used is a long, in order to be able to
test for < 0.  But removing them doesn't seem to cause any
problems.

Thanks,

Arnold



reply via email to

[Prev in Thread] Current Thread [Next in Thread]