什么是最好的方式代表夏令时规则? [英] What is the Best Way to Represent Summer Time Rules?

查看:659
本文介绍了什么是最好的方式代表夏令时规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在数据库中存储不同世界地区的夏令时(夏令时)切换规则。我已经有一种存储区域和子区域的方式(所以整个 一半的澳大利亚/亚利桑那州/纳瓦霍问题是照顾),但我想知道什么是最有效的方案来实现这一点。我看到的两个选项:

I need to store the summer time (daylight saving time) change-over rules for different world regions in a database. I already have a way of storing regions and sub-regions (so the whole "half of Australia"/Arizona/Navaho problem is taken care of), but I'm wondering what the most efficient schema would be to accomplish this. The two options as I see them:


  • 有一个表,其中包含每年的唯一一行和给出开始和结束时间的区域夏天时间以及具体偏移量

  • 有一个表格,用于存储每个区域的公式和有效日期范围(以色列等地区需要的有效范围)

第一个优点是灵活性,因为字面上可以任何。不幸的是,它还需要(a)更多的空间,并且相应地(b)需要大量的工作来获得数据输入。第二个是好的,因为一行可以对应一个区域几十年,但它也需要某种语言解析器和解释器在应用程序层。因为这个数据库将被几种不同的应用程序使用,而没有强大的文本处理能力,我宁愿避开这条路线。

The advantage to the first is flexibility, since literally anything is possible. Unfortunately, it also requires (a) more space, and correspondingly (b) a lot of work to get the data input. The second is nice because one row could correspond to one region for decades, but it also requires some sort of language parser and interpreter in the application layer. Since this database will be used by several different applications written in languages without powerful text processing capabilities, I would rather avoid that route.

我想只是使用zoneinfo或东西像这样,但不幸的是,这不是一个选项在这种情况下。同样,我无法对数据库中的日期,时区和夏令时信息进行规范化,以满足特定用例。

I would love to just use zoneinfo or something like that, but unfortunately that's not an option in this case. Likewise, I cannot normalize the dates, timezone and summer time info must be in the database to satisfy certain use cases.

任何人都有经验做类似的东西?

Does anybody have any experience doing something similar? Likewise, does anyone have any brilliant options that I may have missed?

推荐答案

你几乎注定了第一个选项。你可以预先生成日期,如果你希望有规则关于时间变化的国家,但一些地区没有任何规则,这些变化是由独裁法案或立法投票每年颁布(巴西这样做直到

You're pretty much doomed to the first option. You can pre-generate dates as far ahead as you wish for countries that have "rules" regarding time changes, but some areas do not have any rule and the changes are enacted either by dictatorial fiat or by legislative vote annually (Brazil did so until this year).

这就是为什么所有操作系统供应商每年一次或两次更新时区文件更改 - 因为他们无法生成100%准确的文件程序化。

This is why all OS vendors roll out timezone file changes once or twice a year -- they have to, because they cannot generate a 100% accurate file programatically.

这篇关于什么是最好的方式代表夏令时规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆