Skip to content
Permalink
Browse files
MDEV-29102 system_time_zone is incorrect on Windows when TZ is set
MDEV-19243 introduced a regression on Windows.

In (supposedly rare) case, where environment variable TZ was set,
@@system_time_zone no longer derives from TZ. Instead, it incorrecty
refers to system default time zone, eventhough UTC time conversion
takes TZ into account.

The fix is to restore TZ-aware handling (timezone name derives from
tzname), if TZ is set.
  • Loading branch information
vaintroub committed Oct 11, 2022
1 parent e8101a4 commit 4fec99a
Showing 1 changed file with 17 additions and 7 deletions.
@@ -4303,14 +4303,24 @@ static int init_common_variables()
if (ignore_db_dirs_init())
exit(1);

#ifdef _WIN32
get_win_tzname(system_time_zone, sizeof(system_time_zone));
#elif defined(HAVE_TZNAME)
struct tm tm_tmp;
localtime_r(&server_start_time,&tm_tmp);
const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0];
strmake_buf(system_time_zone, tz_name);
#endif /* HAVE_TZNAME */
localtime_r(&server_start_time, &tm_tmp);

#ifdef HAVE_TZNAME
#ifdef _WIN32
/*
If env.variable TZ is set, derive timezone name from it.
Otherwise, use IANA tz name from get_win_tzname.
*/
if (!getenv("TZ"))
get_win_tzname(system_time_zone, sizeof(system_time_zone));
else
#endif
{
const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0];
strmake_buf(system_time_zone, tz_name);
}
#endif

/*
We set SYSTEM time zone as reasonable default and

0 comments on commit 4fec99a

Please sign in to comment.