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? 2) Can my change break anything else?
3) If is not a dangerous change, there is any reason to do not add this to the next main release code ?