[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...

Issue #11420 has been reported by Koichi Sasada.

11 messages 2015/08/06

[ruby-core:70408] [Ruby trunk - Bug #10904] Time.strptime with %s.%N format should not ignore sec_fraction

From: usa@...
Date: 2015-08-17 07:42:56 UTC
List: ruby-core #70408
Issue #10904 has been updated by Usaku NAKAMURA.

Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE to 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE

ruby_2_1 r51599 merged revision(s) 49788,49790.
note: changed a little to get rid of conflicts.

----------------------------------------
Bug #10904: Time.strptime with %s.%N format should not ignore sec_fraction
https://bugs.ruby-lang.org/issues/10904#change-53813

* Author: Sadayuki Furuhashi
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
* Backport: 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE
----------------------------------------
`Time.strptime` with "%s.%N" format ignores milliseconds, microseconds and nanoseconds.
For example, `Time.strptime("0.123", "%s.%N").tv_usec` returns 0.
Here is the script to reproduce:

```
require 'time'

# sec (this is ok)
t1 = Time.strptime("2015-02-24 21:02:57.321", "%Y-%m-%d %H:%m:%S")
p t1.strftime("%Y-%m-%d %H:%m:%S.%N")   #=> "2015-02-24 21:02:57.000000000"
t2 = Time.strptime("1424842137.321", "%s")
p t2.strftime("%Y-%m-%d %H:%m:%S.%N")   #=> "2015-02-24 21:02:57.000000000"

# msec
t1 = Time.strptime("2015-02-24 21:02:57.321", "%Y-%m-%d %H:%m:%S.%N")
p t1.strftime("%Y-%m-%d %H:%m:%S.%N")   #=> "2015-02-24 21:02:57.321000000"
t2 = Time.strptime("1424842137.321", "%s.%N")
p t2.strftime("%Y-%m-%d %H:%m:%S.%N")   #=> "2015-02-24 21:02:57.000000000"

# usec
t1 = Time.strptime("2015-02-24 21:02:57.654321", "%Y-%m-%d %H:%m:%S.%N")
p t1.strftime("%Y-%m-%d %H:%m:%S.%N")   #=> "2015-02-24 21:02:57.654321000"
t2 = Time.strptime("1424842137.654321", "%s.%N")
p t2.strftime("%Y-%m-%d %H:%m:%S.%N")   #=> "2015-02-24 21:02:57.000000000"

# nsec
t1 = Time.strptime("2015-02-24 21:02:57.987654321", "%Y-%m-%d %H:%m:%S.%N")
p t1.strftime("%Y-%m-%d %H:%m:%S.%N")   #=> "2015-02-24 21:02:57.987654321"
t2 = Time.strptime("1424842137.987654321", "%s.%N")
p t2.strftime("%Y-%m-%d %H:%m:%S.%N")   #=> "2015-02-24 21:02:57.000000000"

p RUBY_VERSION
```

I attached a patch to fix this issue (strptime-s-n-format-sec-fraction-fix.patch).

---Files--------------------------------
strptime-s-n-format-sec-fraction-fix.patch (746 Bytes)
strptime-s-n-format-sec-fraction-fix.2.patch (806 Bytes)


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

In This Thread

Prev Next