cerdea@piatam:~/Downloads$ gcc -o inv-year inv-year.c cerdea@piatam:~/Downloads$ ./inv-year time() = 1555368087 localtime() = 2019-04-15 17:41:27 (mday=15 wday=1, isdst=1) struct tm (after adjustment) = 0009-04-15 17:41:27 (mday=15 wday=1, isdst=1) inv-year: mktime() failed: Value too large for defined data type 1 cerdea@piatam:~/Downloads$
On Mon, Apr 15, 2019 at 3:55 PM Assaf Gordon <assafgor...@gmail.com> wrote: > > Thanks Bernhard, > > On 2019-04-15 2:14 p.m., Bernhard Voelker wrote: > > I can easily reproduce here on my regular openSUSE:Tumbleweed from latest > > git: > > > > $ src/date --debug '+%-Y' -d '- 2010 years' > [....] > > date: error: adding relative date resulted in an invalid date: '(Y-M-D) > > 0009-04-15 22:10:37' > > This makes it easy to pinpoint (hooray for "--debug" :) ). > > This error is given if gnulib's "mktime_z" fails > to convert the adjusted "struct tm" to "time_t" > (adjusted because its tm_year was decremented by 2010). > > https://opengrok.housegordon.com/source/xref/gnulib/lib/parse-datetime.y#2177 > > To see if this is glibc issue, or perhaps an gnulib/mktime_z wrapper > issue, can you (and/or others) try the attached C program? > > It calls time(2)+localtime(3)+mktime(3) to emulate the date adjustment. > > Because the adjustment is to year 9 (about 1961 years before epoch), > the time_t value is negative. perhaps that's the issue? or perhaps > combined with a specific timezone it becomes problematic? > > On my system it gives: > ---- > $ gcc -o inv-year inv-year.c > > $ ./inv-year > time() = 1555361050 > localtime() = 2019-04-15 14:44:10 > (mday=15 wday=1, isdst=1) > struct tm (after adjustment) = 0009-04-15 14:44:10 > (mday=15 wday=1, isdst=1) > mktime() after date adjustment = -61874070118 > ---- > > > regards, > - assaf > > > > > > -- ..hggdh..