Win32: Defer change of timezone name encoding after 3.4
This change will be merged into 3.5 along with other encoding, command line, environment variables, etc. Revert following commits: - bd831bcca534955533d9135d8c2f22d7ae5b9aa8 [Bug #20929] Win32: Use `wcsftime` - 1c15f641cc2bb88fa88123a11036ed58fbf9aa6d [Bug #20929] Win32: Encode timezone name in UTF-8 - 78762b52185aa80ee55c0d49b495aceed863dce2 [Bug #20929] Fix `assert_zone_encoding`
This commit is contained in:
parent
42026ec3da
commit
fb82f3a632
Notes:
git
2024-12-24 04:26:13 +00:00
@ -717,15 +717,13 @@ class TestTime < Test::Unit::TestCase
|
||||
assert_equal("2000-01-01 09:12:34 +091234", t2000.localtime(9*3600+12*60+34).inspect)
|
||||
end
|
||||
|
||||
FIXED_ZONE_ENCODING = (Encoding::UTF_8 if /mswin|mingw/.match?(RUBY_PLATFORM))
|
||||
|
||||
def assert_zone_encoding(time)
|
||||
zone = time.zone
|
||||
assert_predicate(zone, :valid_encoding?)
|
||||
if zone.ascii_only?
|
||||
assert_equal(Encoding::US_ASCII, zone.encoding)
|
||||
else
|
||||
enc = FIXED_ZONE_ENCODING || Encoding.find('locale')
|
||||
enc = Encoding.default_internal || Encoding.find('locale')
|
||||
assert_equal(enc, zone.encoding)
|
||||
end
|
||||
end
|
||||
|
30
time.c
30
time.c
@ -31,10 +31,6 @@
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LOCALE_H)
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#include "id.h"
|
||||
#include "internal.h"
|
||||
#include "internal/array.h"
|
||||
@ -956,11 +952,7 @@ zone_str(const char *zone)
|
||||
str = rb_usascii_str_new(zone, len);
|
||||
}
|
||||
else {
|
||||
#if defined(_WIN32)
|
||||
str = rb_utf8_str_new(zone, len);
|
||||
#else
|
||||
str = rb_enc_str_new(zone, len, rb_locale_encoding());
|
||||
#endif
|
||||
}
|
||||
return rb_fstring(str);
|
||||
}
|
||||
@ -1659,25 +1651,11 @@ localtime_with_gmtoff_zone(const time_t *t, struct tm *result, long *gmtoff, VAL
|
||||
if (zone) {
|
||||
#if defined(HAVE_TM_ZONE)
|
||||
*zone = zone_str(tm.tm_zone);
|
||||
#elif defined(_WIN32)
|
||||
{
|
||||
enum {tz_name_max = 32}; /* numberof(TIME_ZONE_INFORMATION::StandardName) */
|
||||
WCHAR wbuf[tz_name_max + 1];
|
||||
char cbuf[tz_name_max * 4 + 1];
|
||||
size_t wlen = wcsftime(wbuf, numberof(wbuf), L"%Z", &tm);
|
||||
DWORD clen = 0;
|
||||
if (wlen > 0 && wlen < numberof(wbuf)) {
|
||||
clen = WideCharToMultiByte(CP_UTF8, 0, wbuf, wlen, cbuf, sizeof(cbuf), NULL, NULL);
|
||||
}
|
||||
if (clen > 0 && clen < sizeof(cbuf)) {
|
||||
cbuf[clen] = '\0';
|
||||
*zone = zone_str(cbuf);
|
||||
}
|
||||
else {
|
||||
*zone = zone_str(NULL);
|
||||
}
|
||||
}
|
||||
#elif defined(HAVE_TZNAME) && defined(HAVE_DAYLIGHT)
|
||||
# if defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 140
|
||||
# define tzname _tzname
|
||||
# define daylight _daylight
|
||||
# endif
|
||||
/* this needs tzset or localtime, instead of localtime_r */
|
||||
*zone = zone_str(tzname[daylight && tm.tm_isdst]);
|
||||
#else
|
||||
|
@ -785,7 +785,6 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
|
||||
#define HAVE_STRUCT_TIMEVAL 1
|
||||
!if $(MSC_VER) >= 1900
|
||||
#define HAVE_STRUCT_TIMESPEC
|
||||
#define HAVE_LOCALE_H 1
|
||||
!endif
|
||||
!if $(MSC_VER) >= 1600
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user