Project

General

Profile

Actions

Bug #6683

closed

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

Added by pixeltrix (Andrew White) over 12 years ago. Updated over 12 years ago.

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

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0