Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max length of "tzname" field / timezone identifier name

I am trying to find the max length of a timezone identifier. This is the string used as the timezone name (e.g. "America/New_York"). The tz database is not helpful; I could not find implementation details.

Microsoft (.NET Framework 4.5) suggests a max length of 32, but this seems to be a limitation of their registry.

libc points to a limit called "_POSIX_TZNAME_MAX", which is 3 characters long, but this is an absolute minimum requirement for POSIX compliance. Typically, I guess an implementation will use more.

So the real question is: What's an acceptable string length to safely store timezone "tzname" / identifier name?

like image 643
sleblanc Avatar asked Sep 22 '12 17:09

sleblanc


1 Answers

Why not use a container that doesn't care what the length is -- as e.g. std::string ?

Now, it so happens that I was working recently with the TZ db as supplied in the common csv format (eg here in a file from Boost) but the same format is also used in the Boost sources.

With that data, I am seeing a maximum length of 28:

R> library(RcppBDT)                      # R package interfacing Boost Date_Time
Loading required package: Rcpp
R> tz <- new(bdtTz, "America/Chicago")   # init. an object, using my default TZ
R> tznames <- tz$getAllRegions()         # retrieve list of all TZ names
R>
R> length(tznames)                       # total number of TZ identifiers
[1] 381
R>
R> head(tznames)                         # look at first six
[1] "Africa/Abidjan"     "Africa/Accra"       "Africa/Addis_Ababa" 
[4] "Africa/Algiers"     "Africa/Asmera"      "Africa/Bamako"     
R>
R> summary(sapply(tznames, nchar))       # numerical summary of length of each
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      9      13      15      15      17      28 
R>
R> tznames[ nchar(tznames) >= 26 ]       # looking at length 26 and above
[1] "America/Indiana/Indianapolis" "America/Kentucky/Louisville"  
[3] "America/Kentucky/Monticello"  "America/North_Dakota/Center" 
R> 

We can also look at a histogram:

R> library(MASS)
R> truehist(sapply(tznames, nchar), 
+           main="Distribution of TZ identifier length", col="darkgrey")
R>

enter image description here

This uses code which I have in my RcppBDT package's SVN repo on R-Forge but not yet in the CRAN version of the package.

like image 107
Dirk Eddelbuettel Avatar answered Oct 21 '22 23:10

Dirk Eddelbuettel