[Rd] Inappropriate lcl_is_set change in src/extra/tzone/localtime.c

Suharto Anggono Suharto Anggono @uh@rto_@nggono @end|ng |rom y@hoo@com
Wed May 13 10:52:57 CEST 2026


This is about src/extra/tzone/localtime.c , the internal tzcode.

>From my reading, originally, for 'lcl_is_set',
-1 means set not from 'TZ' environment variable;
1 means set from 'TZ' environment variable.

With r90041, 'lcl_is_set' becomes bool with -1 becomes false.

As a static variable without initializer, 'lcl_is_set' is initialized to 0.

Because of

    if (!lcl_is_set) return;

in function 'R_tzsetwall' after change, tzset() with 'TZ' environment variable not set will return without loading time zone definition if tzset() is never called with 'TZ' environment variable set.

The change mostly doesn't cause problem, only because tzset() is called first while TZ=UTC in function 'set_tz' in src/main/datetime.c . However, there is one place where 'set_tz' is not called for current time zone ('tzone' attribute is NULL or has empty string as the first element): function 'do_formatPOSIXlt'. There, time zone information is needed for format "%Z".

> Sys.getenv("TZ", NA)
[1] NA
> x <- .POSIXlt(list(
+ sec=0,min=0L,hour=0L,mday=1L,mon=0L,year=100L,wday=6L,yday=0L,isdst=0L))
> format(x, "%Z")
[1] "   "
> sessionInfo()
R Under development (unstable) (2026-05-11 r90046 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 18363)

Matrix products: default
  LAPACK version 3.12.1

locale:
[1] LC_COLLATE=English_Indonesia.utf8  LC_CTYPE=English_Indonesia.utf8
[3] LC_MONETARY=English_Indonesia.utf8 LC_NUMERIC=C
[5] LC_TIME=English_Indonesia.utf8

time zone: Asia/Jakarta
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_4.7.0


With R 4.6.0 on the same computer:

> Sys.getenv("TZ", NA)
[1] NA
> x <- .POSIXlt(list(
+ sec=0,min=0L,hour=0L,mday=1L,mon=0L,year=100L,wday=6L,yday=0L,isdst=0L))
> format(x, "%Z")
[1] "WIB"
> sessionInfo()
R version 4.6.0 (2026-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 18363)

Matrix products: default
  LAPACK version 3.12.1

locale:
[1] LC_COLLATE=English_Indonesia.utf8  LC_CTYPE=English_Indonesia.utf8
[3] LC_MONETARY=English_Indonesia.utf8 LC_NUMERIC=C
[5] LC_TIME=English_Indonesia.utf8

time zone: Asia/Jakarta
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_4.6.0


The change of 'gmt_is_set' to bool is fine, because 'gmt_is_set' is 1 (TRUE) or 0.



More information about the R-devel mailing list