Unverified Commit a8001d69 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4604 from kou/time-to-s-utf8

Fix Time#to_s encoding on Windows
parents ff43b2b9 effae4ae
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <string.h> #include <string.h>
#endif #endif
#include <stdlib.h>
#define NDIV(x,y) (-(-((x)+1)/(y))-1) #define NDIV(x,y) (-(-((x)+1)/(y))-1)
#define TO_S_FMT "%Y-%m-%d %H:%M:%S " #define TO_S_FMT "%Y-%m-%d %H:%M:%S "
...@@ -931,7 +933,13 @@ mrb_time_to_s(mrb_state *mrb, mrb_value self) ...@@ -931,7 +933,13 @@ mrb_time_to_s(mrb_state *mrb, mrb_value self)
struct mrb_time *tm = time_get_ptr(mrb, self); struct mrb_time *tm = time_get_ptr(mrb, self);
const char *fmt = tm->timezone == MRB_TIMEZONE_UTC ? TO_S_FMT "UTC" : TO_S_FMT "%z"; const char *fmt = tm->timezone == MRB_TIMEZONE_UTC ? TO_S_FMT "UTC" : TO_S_FMT "%z";
size_t len = strftime(buf, sizeof(buf), fmt, &tm->datetime); size_t len = strftime(buf, sizeof(buf), fmt, &tm->datetime);
return mrb_str_new(mrb, buf, len); char *utf8;
mrb_value mrb_string;
buf[len] = '\0';
utf8 = mrb_utf8_from_locale(buf, (int)len);
mrb_string = mrb_str_new_cstr(mrb, utf8);
mrb_utf8_free(utf8);
return mrb_string;
} }
void void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment