Project

General

Profile

Actions

Feature #11220

closed

strptime(%6N)

Added by naruse (Yui NARUSE) over 9 years ago. Updated over 9 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-dev:49026]

Description

strftimeにはマイクロ秒などでの出力を指定する、%6N, %9Nというフォーマットがあります。
一方で、パースを行うstrptimeにはそのような指定子が現在ありません。

そのようなものに対するニーズはぼちぼちあるようなので入れませんか。
http://answers.splunk.com/answers/1946/time-format-and-subseconds.html
https://twitter.com/nalsh/status/606414387352502272

diff --git a/ext/date/date_strptime.c b/ext/date/date_strptime.c
index e318af1..89a6421 100644
--- a/ext/date/date_strptime.c
+++ b/ext/date/date_strptime.c
@@ -611,6 +611,33 @@ date__strptime_internal(const char *str, size_t slen,
                recur("%a %b %e %H:%M:%S %Z %Y");
                goto matched;

+             case '0': case '1': case '2': case '3': case '4':
+             case '5': case '6': case '7': case '8': case '9':
+               {
+                   VALUE n;
+                   size_t w;
+                   int sign = 1;
+                   size_t osi;
+                   w = read_digits(&fmt[fi], &n, 1);
+                   fi += w;
+                   w = NUM2SIZET(n);
+
+                   if (issign(str[si])) {
+                       if (str[si] == '-')
+                           sign = -1;
+                       si++;
+                   }
+                   osi = si;
+                   READ_DIGITS(n, w == 0 ? 9 : w)
+                   if (sign == -1)
+                       n = f_negate(n);
+                   set_hash("sec_fraction",
+                       rb_rational_new2(n,
+                       f_expt(INT2FIX(10),
+                       ULONG2NUM(si - osi))));
+                   goto matched;
+               }
+
              default:
                if (str[si] != '%')
                    fail();

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #6282: strptime and fractions of secondsRejectedtadf (tadayoshi funaba)Actions

Updated by naruse (Yui NARUSE) over 9 years ago

  • Description updated (diff)
Actions #2

Updated by naruse (Yui NARUSE) over 9 years ago

  • Related to Bug #6282: strptime and fractions of seconds added

Updated by naruse (Yui NARUSE) over 9 years ago

  • Status changed from Open to Rejected

%N で読めるからいらないかも

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0