Bug #6683

DateTime#strftime("%s") overflow on 32-bit platform

Added by Andrew White almost 2 years ago. Updated almost 2 years ago.

[ruby-core:46058]
Status:Closed
Priority:Normal
Assignee:tadayoshi funaba
Category:-
Target version:1.9.3
ruby -v:ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux] Backport:

Description

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.

History

#1 Updated by tadayoshi funaba almost 2 years ago

  • Assignee set to tadayoshi funaba

#2 Updated by tadayoshi funaba almost 2 years ago

  • Status changed from Open to Closed

#3 Updated by Yui NARUSE almost 2 years ago

Fixed in r36265.

Also available in: Atom PDF