从Olson时区转换为Posix时区

huangapple go评论63阅读模式
英文:

Converting from Olson time zone to Posix time zone

问题

C/C++ 中是否有一种方法可以将 Olson 时区格式转换为 POSIX 时区格式。

示例:对于奥克兰
Olson 时区格式:TZ="Pacific/Auckland"
Posix 时区格式:TZ="NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0"

英文:

Is there a way in C/C++ to convert from Olson time zone format to POSIX time zone format.

Example: for Auckland
Olson time zone format: TZ="Pacific/Auckland"
Posix time zone format: TZ="NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0"

答案1

得分: 2

一般来说,这是不可能的,因为POSIX时区格式只允许每年零次或两次UTC偏移更改,不允许为不同年份制定不同的规则。IANA(Olson)数据库比这更灵活。

如果你允许多个POSIX时区和一个POSIX时区有效的起始/结束时间,那几乎可以实现,但不容易。

我一直在开发一个工具来实现这个目标,需要对POSIX时区格式进行扩展,以允许"永久DST"。这是通过允许字符串以偏移量开始,使初始标准缩写成为可选项,并允许规则集(以,开头的所有内容)也是可选的。例如:

"EST5"产生一个恒定的偏移量为-5小时,0小时保存和"EST"缩写。
"5EDT"产生一个恒定的偏移量为-4小时,1小时保存和"EDT"缩写。

即使有了这些扩展,我还不能确定是否能够完全捕获完整的IANA时区信息。这个工具仍在开发中。

以下是我目前对太平洋/奥克兰的信息(未经核实):

太平洋/奥克兰
*
LMT-11:39:04
1868-11-01 12:20:56
NZMT-11:30
1927-11-05 14:30:00
NZMT-11:30NZST,M11.1.0,M3.1.0
1928-10-13 14:30:00
NZMT-11:30NZST-12,M10.2.0,M3.3.0
1933-10-07 14:30:00
NZMT-11:30NZST-12,M10.2.0,M4.5.0
1934-09-29 14:30:00
NZMT-11:30NZST-12,M9.5.0,M4.5.0
1940-09-28 14:30:00
-11:30NZST-12
1945-12-31 12:00:00
NZST-12
1974-11-02 14:00:00
NZST-12NZDT,M11.1.0,M2.5.0/3
1975-10-25 14:00:00
NZST-12NZDT,M10.5.0,M3.1.0/3
1989-10-07 14:00:00
NZST-12NZDT,M10.2.0,M3.3.0/3
1990-10-06 14:00:00
NZST-12NZDT,M10.1.0,M3.3.0/3
2007-09-29 14:00:00
NZST-12NZDT,M9.5.0,M4.1.0/3
*

时间戳隐含地是UTC。第一个*表示时间的开始,最后一个*表示时间的结束。这些都需要由读取这个转换后的数据库的客户端来解释。

英文:

In general it is not possible because the POSIX time zone format only allows for zero or two UTC offset changes per year, and does not allow for different rules for different years. The IANA (Olson) data base is more flexible than that.

If you allow for multiple Posix time zones and a start/end for when that Posix time zone is valid, it is almost possible, but not easy.

I've been working on a tool to do this, and needed to make an extension to the Posix time zone format to allow for "permanent DST". This is done by allowing the string to begin with an offset, making the initial standard abbreviation optional, and allowing the rule set (everything beginning with ,) also be optional. Example:

"EST5" yields a constant offset of -5h with 0h save and "EST abbreviation.
"5EDT" yields a constant offset of -4h with 1h save and "EDT" abbreviation.

Even with these extensions, I'm not positive it is possible to capture a complete IANA time zone with Posix time zones. This tool is still under development.

Here is what I current have for Pacific/Auckland (it is unchecked):

Pacific/Auckland
*
LMT-11:39:04
1868-11-01 12:20:56
NZMT-11:30
1927-11-05 14:30:00
NZMT-11:30NZST,M11.1.0,M3.1.0
1928-10-13 14:30:00
NZMT-11:30NZST-12,M10.2.0,M3.3.0
1933-10-07 14:30:00
NZMT-11:30NZST-12,M10.2.0,M4.5.0
1934-09-29 14:30:00
NZMT-11:30NZST-12,M9.5.0,M4.5.0
1940-09-28 14:30:00
-11:30NZST-12
1945-12-31 12:00:00
NZST-12
1974-11-02 14:00:00
NZST-12NZDT,M11.1.0,M2.5.0/3
1975-10-25 14:00:00
NZST-12NZDT,M10.5.0,M3.1.0/3
1989-10-07 14:00:00
NZST-12NZDT,M10.2.0,M3.3.0/3
1990-10-06 14:00:00
NZST-12NZDT,M10.1.0,M3.3.0/3
2007-09-29 14:00:00
NZST-12NZDT,M9.5.0,M4.1.0/3
*

The time stamps are implicitly UTC. The first * indicates the beginning of time, and the last * indicates the end of time. Those are open to interpretation of the client reading this transformed database.

huangapple
  • 本文由 发表于 2023年5月28日 13:31:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76350087.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定