"tzname"字段/时区标识符名称的最大长度

sle*_*anc 17 database schema timezone

我试图找到时区标识符的最大长度.这是用作时区名称的字符串(例如"America/New_York").tz数据库没有帮助; 我找不到实施细节.

Microsoft(.NET Framework 4.5)建议最大长度为32,但这似乎是其注册表的限制.

libc指向一个名为"_POSIX_TZNAME_MAX"的限制,长度为3个字符,但这是POSIX合规性的绝对最低要求.通常,我猜一个实现将使用更多.

所以真正的问题是:安全存储时区"tzname"/标识符名称的字符串长度是多少?

Dir*_*tel 22

为什么不使用不关心长度的容器 - 例如std::string

现在,碰巧我最近使用普通csv格式提供的TZ数据库(例如,来自CERN的文件),但同样的格式也用于Boost源代码.

有了这些数据,我发现最大长度为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> 
Run Code Online (Sandbox Code Playgroud)

我们还可以查看直方图:

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

在此输入图像描述

这使用了我的RcppBDT软件包在R-Forge上SVN repo中的代码,但还没有在软件包的CRAN版本中.

  • 我可以在本地zoneinfo目录中找到的最长名称是`right / America / Argentina / ComodRivadavia`(38个字符)。除所有`right / ...`外,还有`posix / ...`名称。这些名称在[此处](http://askubuntu.com/a/34957/6969)进行了说明。 (3认同)
  • 惊人的答案!实际上,我不能使用变长字符串,因为我想将这些字符串存储在数据库中.起初,我不想使用任意长的字段,但我认为我设置了一个40字符长的字符串[1].我将这些放在一个单独的表中,并使用外键引用它们.1:有一个时区("America/Argentina/ComodRivadavia")实际上是32个字符长.将来可能会有其他同样长的名字. (2认同)
  • varchars实际上不需要指定的长度吗? (2认同)