Bug #5399
closedTime.strptime does not correctly parse seconds since epoch
Description
Reproducing the bug inside the IRB:
Time.strptime("1", "%s")
=> 2011-10-03 15:51:02 -0700
as opposed to:
Date.strptime("1", "%s").to_time
=> 1970-01-01 00:00:00 -0800
The docs read that Time.strptime relies on Date._strptime to do the parsing, and then converts it to a Time object. Date._strptime returns the time only as seconds (with "%s" as the format string):
Date.send(:_strptime, "100000", "%s")
=> {:seconds=>100000}
Class Date seems to check for this case (see Date.rewrite_frags) but class Time does not; Time seems to assume that Date._strptime will return a hash with all of the key/values necessary to correctly call Time.make_time:
File lib/time.rb, line 277¶
d = Date._strptime(date, format)
. . .
make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
Updated by naruse (Yui NARUSE) about 14 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r33398.
Christopher, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- lib/time.rb (Time.strptime): use Time.at if d[:seconds] is set.
Reported by Christopher Eberz. [ruby-core:39903] Bug #5399