rubinius/rubinius — pull request #2364 by r-stu31 (2013-05-27 09:53:00+00:00)
Title: Correct isdst argument in time tests

The tests *Time.local creates a time based on given C-style gmtime arguments, interpreted in the local time zone* and *Time.mktime creates a time based on given C-style gmtime arguments, interpreted in the local time zone* are failing under NetBSD, because the `isdst` argument (`:ignored`) evaluates to a true-value (https://github.com/rubinius/rubinius/blob/master/kernel/common/time.rb#L80), but the time point is not in a DST season.

The underlying cause of failure is EOVERFLOW from the system's `mktime()` (https://github.com/rubinius/rubinius/blob/master/vm/util/time64.c#L294 and later on https://github.com/rubinius/rubinius/blob/master/vm/util/time64.c#L333 too). Here is a test code I wrote to debug this problem:
```C
#include
#include
#include
#include
#include

int
main(int argc, char *argv[])
{
time_t t;
struct tm* tm;

tm = malloc(sizeof *tm);
tm->tm_year = 100;
tm->tm_mon = 0;
tm->tm_mday = 1;
tm->tm_hour = 20;
tm->tm_min = 15;
tm->tm_sec = 1;
tm->tm_wday = -1;
tm->tm_yday = 32639;
tm->tm_isdst = 1; /* <===== PROBLEM */
tm->tm_gmtoff = 0;
tm->tm_zone = NULL;

t = mktime(tm);
if (t == -1) {
printf("::: errno = %d :: %s\n", errno, strerror(errno));
} else {
printf("::: t = %d\n", t);
}

return 0;
}
```
simulating the test, the output under NetBSD is:
```
$ env TZ="PST8:00:00" ./mktime
::: errno = 84 :: Value too large to be stored in data type
```
under Debian Linux:
```
$ env TZ="PST8:00:00" ./mktime
::: t = 946786501
$
```

MRI does not care when given incorrect `isdst` in this case under NetBSD and the tests are not failing.

One possible "fix" is including the `errno` of EOVERFLOW to the check here: https://github.com/rubinius/rubinius/blob/master/vm/util/time64.c#L334 and I also think, that we should include the same code after the first call to `mktime()` here: https://github.com/rubinius/rubinius/blob/master/vm/util/time64.c#L294 to get correct results for years out of `struct tm` int range.