Issue #9951 has been updated by Heesob Park.


Time seems to truncate the fraction of second in strftime.

Here is a patch

~~~diff
diff --git a/strftime.c b/strftime.c
index 83550e9..a0a7de5 100644
--- a/strftime.c
+++ b/strftime.c
@@ -705,7 +705,7 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
                                 else {
                                         int i;
                                         for (i = 0; i < 9-precision; i++)
-                                                subsec /= 10;
+                                                subsec = (int)(subsec/10.0+0.5);
                                         snprintf(s, endp - s, "%0*ld", precision, subsec);
                                         s += precision;
                                 }
@@ -725,7 +725,7 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
                                         n *= 10;
                                 if (n != 1)
                                         subsec = mul(subsec, INT2FIX(n));
-                                subsec = div(subsec, INT2FIX(1));
+                                subsec = div(add(subsec,DBL2NUM(0.5)), INT2FIX(1));
 
                                 if (FIXNUM_P(subsec)) {
                                         (void)snprintf(s, endp - s, "%0*ld", precision, FIX2LONG(subsec));
~~~

----------------------------------------
Bug #9951: DateTime.strftime and Time.strftime differ in how they treat "%L"
https://bugs.ruby-lang.org/issues/9951#change-47261

* Author: David Chelimsky
* Status: Assigned
* Priority: Normal
* Assignee: Akira Tanaka
* Category: core
* Target version: 
* ruby -v: 1.9.3 - 2.1.1
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
~~~ruby
DateTime.new(2014,1,2,3,4,5.678).strftime("%L")
# => "678"
Time.new(2014,1,2,3,4,5.678).strftime("%L")
# => "677"
~~~

I think these should both produce "678", but at the very least they should produce the same number so users don't have to special case one or the other. I realize there is floating point math under the hood here, but that's an implementation detail I don't think users should care about in this case.



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