From: "pixeltrix (Andrew White)" <andyw@...>
Date: 2012-07-02T01:17:41+09:00
Subject: [ruby-core:46058] [ruby-trunk - Bug #6683][Open] DateTime#strftime("%s") overflow on 32-bit platform


Issue #6683 has been reported by pixeltrix (Andrew White).

----------------------------------------
Bug #6683: DateTime#strftime("%s") overflow on 32-bit platform
https://bugs.ruby-lang.org/issues/6683

Author: pixeltrix (Andrew White)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 1.9.3
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux] 


The improvements to date and time in 1.9.3 introduced a regression from 1.9.2 with respect to DateTime#strftime("%s") (%s is seconds since the UNIX epoch). e.g.

# Ruby 1.9.2p320
1.9.2p320 :001 > require 'date'
1.9.2p320 :002 > require 'time'
1.9.2p320 :003 > DateTime.civil(1850).strftime('%s')
 => "-3786825600" 

# Ruby 1.9.3p194
1.9.3p194 :001 > require 'date'
1.9.3p194 :002 > require 'time'
1.9.3p194 :003 > DateTime.civil(1850).strftime('%s')
 => "508141696" 

The transition occurs at midnight on 23rd December 1935:

1.9.3p194 :006 > DateTime.civil(1935, 12, 23, 23, 59, 59).strftime('%s')
 => "1073790847" 
1.9.3p194 :007 > DateTime.civil(1935, 12, 24, 0, 0, 0).strftime('%s')
 => "-1073692800" 

Dates in the far future seem to be okay:

1.9.3p194 :013 > DateTime.civil(20000000).strftime('%s')
 => "631076872780800" 

I've tried tracking it down in date_strftime.c but haven't got very far yet.


-- 
http://bugs.ruby-lang.org/