Feature #3547
closed%:z and %::z for strftime
Description
=begin
strftime で %:z と %::z という指定を可能にするのはどうでしょうか。
% ./ruby -e 'p Time.now.strftime("%z %:z %::z")'
"+0900 +09:00 +09:00:00"
時差をフォーマットするのに現在は %z がありますが、これは +hhmm という形です。
これは RFC 822 形式の時刻を表現するにはちょうどいいのですが、
XML Schema や RFC 3339 や W3CDTF で使う、コロンが入った +hh:mm という
形式とは合いません。
そして、最近知ったのですが、GNU coreutils の date には %:z という指定で
+hh:mm という形式を生成する機能があります。
また、コロンをふたつにして %::z とすると +hh:mm:ss と秒まで生成します。
というわけで、Ruby でも %:z と %::z をサポートするのはどうでしょう。
なお、コロンが入った形式はその文字列自体を見て時刻の類であることがわかるので
間違いが起きにくく、この型式はそれ自体良いものだと思います。
% svn diff --diff-cmd diff -x '-u -p'
Index: time.c¶
--- time.c (revision 28563)
+++ time.c (working copy)
@@ -4346,7 +4346,9 @@ strftimev(const char *fmt, VALUE time)
- %X - Preferred representation for the time alone, no date
- %y - Year without a century (00..99)
- %Y - Year with century
-
- %z - Time zone as hour offset from UTC (e.g. +0900)
-
- %z - Time zone as hour and minute offset from UTC (e.g. +0900)
-
-
- %Z - Time zone name
- %% - Literal ``%'' character
Index: strftime.c¶
--- strftime.c (revision 28563)
+++ strftime.c (working copy)
@@ -215,7 +215,7 @@ rb_strftime_with_timespec(char s, size_
#endif
#endif / HAVE_TM_NAME /
#endif / HAVE_TM_ZONE */
- int precision, flags;
- int precision, flags, colons;
char padding;
enum {LEFT, CHCASE, LOWER, UPPER, LOCALE_O, LOCALE_E};
#define BIT_OF(n) (1U<<(n))
@@ -348,6 +348,7 @@ rb_strftime_with_timespec(char *s, size_
precision = -1;
flags = 0;
padding = 0; -
again:
switch (*++format) {
case '\0':
@@ -530,13 +531,31 @@ rb_strftime_with_timespec(char *s, size_
* us that muck around with various message processors.
/
case 'z': / time zone offset east of GMT e.g. -0600 */
rb_intern("round"), 0));
#if 0
#ifdef HAVE_TM_NAME
/*
@@ -583,11 +602,22 @@ rb_strftime_with_timespec(char *s, size_
} else {
*s++ = '+';
}
precision, off / 3600);
#endif /* MAILHEADER_EXT */
@@ -839,6 +869,11 @@ rb_strftime_with_timespec(char *s, size_
padding = ' ';
goto again;
--
[田中 哲][たなか あきら][Tanaka Akira]
=end