diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-08 02:35:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-08 02:35:31 +0000 |
commit | ee58c638b8d10d2ea10faadbc7b34515d2f2e351 (patch) | |
tree | 7716f26c1b8415e0e639bf093e339cdabb13c5aa /strftime.c | |
parent | e0bc5e49ffc1a013705e1e287967139425912974 (diff) |
Timezone support by Time [Feature #14850]
* strftime.c (rb_strftime): support timezone object by `%z`.
* time.c (time_init_1, time_new_timew, time_getlocaltime): accept
timezone object as `off`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'strftime.c')
-rw-r--r-- | strftime.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/strftime.c b/strftime.c index ec656f6130..c864076f10 100644 --- a/strftime.c +++ b/strftime.c @@ -226,8 +226,8 @@ format_value(VALUE val, int base) */ static VALUE rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, - rb_encoding *enc, const struct vtm *vtm, VALUE timev, - struct timespec *ts, int gmt, size_t maxsize) + rb_encoding *enc, VALUE time, const struct vtm *vtm, + VALUE timev, struct timespec *ts, int gmt, size_t maxsize) { size_t len = RSTRING_LEN(ftime); char *s = RSTRING_PTR(ftime); @@ -246,6 +246,7 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, #ifdef MAILHEADER_EXT int sign; #endif + VALUE zone = Qnil; /* various tables, useful in North America */ static const char days_l[][10] = { @@ -317,7 +318,7 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, len = s - start; \ rb_str_set_len(ftime, len); \ if (!rb_strftime_with_timespec(ftime, (fmt), rb_strlen_lit(fmt), \ - enc, vtm, timev, ts, gmt, maxsize)) \ + enc, time, vtm, timev, ts, gmt, maxsize)) \ return 0; \ s = RSTRING_PTR(ftime); \ i = RSTRING_LEN(ftime) - len; \ @@ -623,7 +624,10 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, i = 0; } else { - tp = RSTRING_PTR(vtm->zone); + if (NIL_P(zone)) { + zone = rb_time_zone_abbreviation(vtm->zone, time); + } + tp = RSTRING_PTR(zone); if (enc) { for (i = 0; i < TBUFSIZE && tp[i]; i++) { if ((unsigned char)tp[i] > 0x7F) { @@ -912,34 +916,34 @@ strftime_size_limit(size_t format_len) } VALUE -rb_strftime(const char *format, size_t format_len, - rb_encoding *enc, const struct vtm *vtm, VALUE timev, int gmt) +rb_strftime(const char *format, size_t format_len, rb_encoding *enc, + VALUE time, const struct vtm *vtm, VALUE timev, int gmt) { VALUE result = rb_enc_str_new(0, 0, enc); return rb_strftime_with_timespec(result, format, format_len, enc, - vtm, timev, NULL, gmt, + time, vtm, timev, NULL, gmt, strftime_size_limit(format_len)); } VALUE -rb_strftime_timespec(const char *format, size_t format_len, - rb_encoding *enc, const struct vtm *vtm, struct timespec *ts, int gmt) +rb_strftime_timespec(const char *format, size_t format_len, rb_encoding *enc, + VALUE time, const struct vtm *vtm, struct timespec *ts, int gmt) { VALUE result = rb_enc_str_new(0, 0, enc); return rb_strftime_with_timespec(result, format, format_len, enc, - vtm, Qnil, ts, gmt, + time, vtm, Qnil, ts, gmt, strftime_size_limit(format_len)); } #if 0 VALUE -rb_strftime_limit(const char *format, size_t format_len, - rb_encoding *enc, const struct vtm *vtm, struct timespec *ts, +rb_strftime_limit(const char *format, size_t format_len, rb_encoding *enc, + VALUE time, const struct vtm *vtm, struct timespec *ts, int gmt, size_t maxsize) { VALUE result = rb_enc_str_new(0, 0, enc); return rb_strftime_with_timespec(result, format, format_len, enc, - vtm, Qnil, ts, gmt, maxsize); + time, vtm, Qnil, ts, gmt, maxsize); } #endif |