英文:
Timezone and DST calculation in date/time libraries
问题
如果一个国家(比如美国)决定整年都保持夏令时,会发生什么? 换句话说,库必须包含时区和夏令时日期的列表。 如果一个国家的夏令时规则发生改变,是否需要发布新版本的库以更新夏令时数值?
英文:
I am using specifically Luxon. However this question applies to all date/time libraries.
What happens if a country (say the USA) decides to remain in DST the whole year? To the point, libraries must contain a list of timezones and DST dates. If DST changes for a country, does a new version of the library need to be published with the updated DST values?
答案1
得分: 3
不一定是一个新的库,但是至少是一个新的数据库:https://www.iana.org/time-zones。
IANA 不是唯一的时区数据库,但它可能是最广泛使用的。它每年都会更新多次。去年有7次更新(2022年)。
英文:
Not necessarily a new library but yes, at least a new database: https://www.iana.org/time-zones.
IANA isn't the only timezone database, but it is probably the most widely used. And it gets updated several times a year. There were 7 updates last year (2022).
答案2
得分: 3
这取决于使用的库。
有些库捆绑了它们自己的时区数据,需要定期更新以接收此类更新。示例包括:
- moment-timezone(JavaScript)
- pytz(Python)
- Joda-Time(Java)
- NodaTime(.NET)
- TimezoneDB(PHP)
- ICU(C/C++ 和 Java)
其他库从它们运行的主机环境中获取时区数据,该主机环境可能会从库或主机操作系统获取其时区数据。示例包括:
- Luxon(JavaScript),它使用
Intl
,通常通过由浏览器(或 Node.js)分发的ICU实现 zoneinfo
(内置于Python),如果可用,它使用主机操作系统的时区数据,否则使用python的tzdata
包。java.time
(内置于Java),它使用随Java运行时分发的时区数据TimeZoneInfo
(内置于.NET),它使用主机操作系统的时区数据
这些列表不打算全面。
数据的最终来源通常是 IANA TZ Database。所有捆绑它们自己时区数据的库都是从那里派生的。
但是,微软还单独维护了 Windows的时区数据。它仍然在Windows平台上由.NET使用,以及其他较旧的Windows技术,如Win32 API。
英文:
It depends on the library.
Some libraries bundle their own time zone data and needed to be updated regularly to receive such updates. Examples include:
- moment-timezone (JavaScript)
- pytz (Python)
- Joda-Time (Java)
- NodaTime (.NET)
- TimezoneDB (PHP)
- ICU (C/C++ & Java)
Other libraries take their time zone data from from the host environment they run within, which might in-turn take their time zone data from a library, or from the host OS. Examples include:
- Luxon (JavaScript), which uses
Intl
, which is most commonly implemented via ICU, which is distributed by the browser (or Node.js) zoneinfo
(built-in to Python), which uses the host OS time zone data if available, or the pythontzdata
package if not.java.time
(built-in to Java), which uses the time zone data distributed with the Java RuntimeTimeZoneInfo
(built-in to .NET), which uses the time zone data from the host operating system
These lists are not intended to be comprehensive.
The ultimate source of the data is usually the IANA TZ Database. All libraries that ship their own time zone data derive it from there.
However, Microsoft also still maintains time zone data for Windows separately. It is still used by .NET on Windows platforms, and other older Windows technologies such as Win32 APIs.
答案3
得分: 2
No. Luxon的感知时间区域是否具有夏令时并不来自它自己的数据文件;而是来自JS运行时(浏览器或Node),通过Intl API将它们公开。Intl API又使用运行时捆绑的ICU数据中的TZ规则。因此,当浏览器(或其他JS宿主)更新时,Luxon获取到这些新规则。
英文:
No. Luxon's sense of when time zone's have DSTs doesn't come from its own data file; it comes from the JS runtime (the browser, or Node), which exposes them through the Intl API. The Intl API, in turn, uses the TZ rules from the ICU data bundled with the runtime. So when the browser (or other JS host) updates, Luxon gets those new rules.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论