Bug 17186

Summary: Wishlist: [patch] Make Sys.timezone() work on Debian
Product: R Reporter: Mikko Korpela <mvkorpel>
Component: WishlistAssignee: R-core <R-core>
Status: CLOSED FIXED    
Severity: enhancement CC: edd, maechler
Priority: P5    
Version: R-devel (trunk)   
Hardware: All   
OS: Linux-Debian   
Attachments: Suggested patch

Description Mikko Korpela 2016-11-29 12:22:02 UTC
Created attachment 2195 [details]
Suggested patch

When the TZ environment variable is not set, Sys.timezone() returns NA on recent (i.e. not ancient) versions of Linux distributions derived from Debian (unless they choose to modify this behavior). On these systems, /etc/localtime is not a symbolic link from which the name of the time zone can be extracted, but a regular file (copy of the time zone description). Instead, /etc/timezone contains the name of the time zone. [1]

The attached patch reads /etc/timezone and checks that the corresponding time zone file exists in /usr/share/zoneinfo, and that the latter is of the same size as /etc/localtime (likely a copy of the same file). If so, the name read from /etc/timezone is returned. This whole code branch is only entered if the previous time zone detection methods fail.

This was tested on Ubuntu 14.04.5 LTS. After applying the patch, the result of Sys.timezone() on this computer is "Europe/Helsinki" which matches the pre-patch result on my old Macbook (OS X 10.7.5).

[1] https://wiki.debian.org/TimeZoneChanges

> sessionInfo()
R Under development (unstable) (2016-11-29 r71700)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            

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

loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0
Comment 1 Dirk Eddelbuettel 2016-11-29 16:59:40 UTC
Thumbs up.  

That is essentially what my micropackage 'gettz' does but as Duncan M remarked when he approved the initial CRAN upload, the change really belongs into base R.
Comment 2 Martin Maechler 2016-12-30 16:16:51 UTC
Thank you, Mikoo, very much.

This has been fixed already > 3 weeks ago,
r71729 | maechler | 2016-12-05
both in R-devel and R-patched