I'm running into discrepancies running the following command on different Ruby installations:
Time.utc(2099, 12, 31, 23, 59, 59)
On some systems I get an error, on some a valid response.
Any ideas why this may be?
I'm running into discrepancies running the following command on different Ruby installations:
Time.utc(2099, 12, 31, 23, 59, 59)
On some systems I get an error, on some a valid response.
Any ideas why this may be?
The Ruby Time class defines its maximum and minimum values based on the size of the platform's time_t
type. The following is from Ruby's time.c
file:
#if SIZEOF_TIME_T == SIZEOF_LONG
typedef unsigned long unsigned_time_t;
#elif SIZEOF_TIME_T == SIZEOF_INT
typedef unsigned int unsigned_time_t;
#elif SIZEOF_TIME_T == SIZEOF_LONG_LONG
typedef unsigned LONG_LONG unsigned_time_t;
#else
# error cannot find integer type which size is same as time_t.
#endif
#define TIMET_MAX (~(time_t)0 <= 0 ?
(time_t)((~(unsigned_time_t)0) >> 1) : (~(unsigned_time_t)0))
#define TIMET_MIN (~(time_t)0 <= 0 ?
(time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1)) : (time_t)0)
The size of time_t
varies on different platforms. On most modern platforms, time_t
is 64 bits, which will allow your time on 31 December 2009 to be represented. On older platforms (including Microsoft's Visual C++ .NET 2003 compiler) time_t
is only 32 bits, which gives you a maximum possible value of 19 January 2038 03:14:07 UTC. Trying to create your time on such a platform will give you a 'time out of range' error.