summaryrefslogtreecommitdiff
path: root/strftime.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-29 08:28:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-29 08:28:13 +0000
commit39a3d1793b67df8ef1aa48e2f813dcac13814544 (patch)
tree00cd78519b251ca3995f7e1c31e7de5aa60ba90e /strftime.c
parent241902e7091a0ad514683488020011e827ad7750 (diff)
strftime.c: triple colons modifier
partially borrowed from ext/date. * strftime.c (rb_strftime_with_timespec): support GNU extension triple colons modifier. [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'strftime.c')
-rw-r--r--strftime.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/strftime.c b/strftime.c
index 8d301e1115..ccb180b57b 100644
--- a/strftime.c
+++ b/strftime.c
@@ -460,6 +460,18 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
#ifdef MAILHEADER_EXT
case 'z': /* time zone offset east of GMT e.g. -0600 */
+ if (gmt) {
+ off = 0;
+ }
+ else {
+ off = NUM2LONG(rb_funcall(vtm->utc_offset, rb_intern("round"), 0));
+ }
+ if (off < 0) {
+ off = -off;
+ sign = -1;
+ } else {
+ sign = +1;
+ }
switch (colons) {
case 0: /* %z -> +hhmm */
precision = precision <= 5 ? 2 : precision-3;
@@ -476,22 +488,25 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
NEEDS(precision + 7);
break;
+ case 3: /* %:::z -> +hh[:mm[:ss]] */
+ if (off % 3600 == 0) {
+ precision = precision <= 3 ? 2 : precision-1;
+ NEEDS(precision + 3);
+ }
+ else if (off % 60 == 0) {
+ precision = precision <= 6 ? 2 : precision-4;
+ NEEDS(precision + 4);
+ }
+ else {
+ precision = precision <= 9 ? 2 : precision-7;
+ NEEDS(precision + 9);
+ }
+ break;
+
default:
format--;
goto unknown;
}
- if (gmt) {
- off = 0;
- }
- else {
- off = NUM2LONG(rb_funcall(vtm->utc_offset, rb_intern("round"), 0));
- }
- if (off < 0) {
- off = -off;
- sign = -1;
- } else {
- sign = +1;
- }
i = snprintf(s, endp - s, (padding == ' ' ? "%+*ld" : "%+.*ld"),
precision + 1, sign * (off / 3600));
if (i < 0) goto err;
@@ -500,12 +515,16 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
}
s += i;
off = off % 3600;
+ if (colons == 3 && off == 0)
+ continue;
if (1 <= colons)
*s++ = ':';
i = snprintf(s, endp - s, "%02d", (int)(off / 60));
if (i < 0) goto err;
s += i;
off = off % 60;
+ if (colons == 3 && off == 0)
+ continue;
if (2 <= colons) {
*s++ = ':';
i = snprintf(s, endp - s, "%02d", (int)off);