summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2025-02-17 21:46:47 +0900
committerNobuyoshi Nakada <[email protected]>2025-02-19 18:27:32 +0900
commit3f07bc76ff6a11232d9f18e5eaa31835c195e8f0 ()
treef94ee52c712179414e6295338af79f57b30e20c5
parentbd84c75a013042f4feefa4616ab119394b3bbf24 (diff)
[Bug #21144] Win32: Use Windows time zone ID if TZ is not set
If the TZ environment variable is not set, the time zone names retrieved from the system are localized for UI display and may vary across editions and language packs for the same time zone. Use the time zone IDs that are invariant across environments instead.
Notes: Merged: https://.com/ruby/ruby/pull/12765
-rw-r--r--hash.c8
-rw-r--r--internal/time.h5
-rw-r--r--time.c57
3 files changed, 60 insertions, 10 deletions
@@ -5016,7 +5016,7 @@ env_name(volatile VALUE *s)
static VALUE env_aset(VALUE nm, VALUE val);
static void
-reset_by_modified_env(const char *nam)
{
/*
* ENV['TZ'] = nil has a special meaning.
@@ -5025,7 +5025,7 @@ reset_by_modified_env(const char *nam)
* This hack might works only on Linux glibc.
*/
if (ENVMATCH(nam, TZ_ENV)) {
- ruby_reset_timezone();
}
}
@@ -5033,7 +5033,7 @@ static VALUE
env_delete(VALUE name)
{
const char *nam = env_name(name);
- reset_by_modified_env(nam);
VALUE val = getenv_with_lock(nam);
if (!NIL_P(val)) {
@@ -5439,7 +5439,7 @@ env_aset(VALUE nm, VALUE val)
get_env_ptr(value, val);
ruby_setenv(name, value);
- reset_by_modified_env(name);
return val;
}
@@ -28,7 +28,10 @@ struct timeval rb_time_timeval(VALUE);
RUBY_SYMBOL_EXPORT_BEGIN
/* time.c (export) */
void ruby_reset_leap_second_info(void);
-void ruby_reset_timezone(void);
RUBY_SYMBOL_EXPORT_END
#endif /* INTERNAL_TIME_H */
@@ -45,6 +45,10 @@
#include "ruby/util.h"
#include "timev.h"
#include "builtin.h"
static ID id_submicro, id_nano_num, id_nano_den, id_offset, id_zone;
@@ -703,10 +707,51 @@ static VALUE tm_from_time(VALUE klass, VALUE time);
bool ruby_tz_uptodate_p;
void
-ruby_reset_timezone(void)
{
ruby_tz_uptodate_p = false;
ruby_reset_leap_second_info();
}
@@ -1653,11 +1698,9 @@ 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(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
@@ -5863,6 +5906,10 @@ rb_time_zone_abbreviation(VALUE zone, VALUE time)
void
Init_Time(void)
{
id_submicro = rb_intern_const("submicro");
id_nano_num = rb_intern_const("nano_num");
id_nano_den = rb_intern_const("nano_den");