或者是否有时区gem允许我配置rails以使用Windows格式?
这是一个我已经开始帮助转换的数组,但有一点我不是100%肯定.
DAYLIGHT = [ {name: 'Dateline Daylight Time',offset: -12,alt: 'International Date Line West'},{name: 'UTC-11',offset: -11,alt: ''},{name: 'Hawaiian Daylight Time',offset: -10,alt: 'Hawaii'},{name: 'Alaskan Daylight Time',offset: -9,alt: 'Alaska'},{name: 'Pacific Daylight Time (Mexico)',offset: -8,{name: 'Pacific Daylight Time',alt: 'Pacific Time (US & Canada)'},{name: 'US Mountain Daylight Time',offset: -7,alt: 'Mountain Time (US & Canada)'},{name: 'Mountain Daylight Time (Mexico)',{name: 'Mountain Daylight Time',{name: 'Central America Daylight Time',offset: -6,alt: 'Central Time (US & Canada)'},{name: 'Central Daylight Time',{name: 'Central Daylight Time (Mexico)',{name: 'Canada Central Daylight Time',{name: 'SA Pacific Daylight Time',offset: -5,{name: 'Eastern Daylight Time',alt: 'Eastern Time (US & Canada)'},{name: 'US Eastern Daylight Time',{name: 'Venezuela Daylight Time',offset: -4.5,{name: 'Paraguay Daylight Time',offset: -4,{name: 'Atlantic Daylight Time',{name: 'Central Brazilian Daylight Time',{name: 'SA Western Daylight Time',{name: 'Pacific SA Daylight Time',{name: 'Newfoundland Daylight Time',offset: -3.5,{name: 'E. South America Daylight Time',offset: -3,{name: 'Argentina Daylight Time',{name: 'SA Eastern Daylight Time',{name: 'Greenland Daylight Time',{name: 'Montevideo Daylight Time',{name: 'Bahia Daylight Time',{name: 'UTC-02',offset: -2,{name: 'Mid-Atlantic Daylight Time',{name: 'Azores Daylight Time',offset: -1,{name: 'Cabo Verde Daylight Time',{name: 'Morocco Daylight Time',offset: 0,{name: 'Coordinated Universal Time',{name: 'GMT Daylight Time',{name: 'Greenwich Daylight Time',{name: 'W. Europe Daylight Time',offset: 1,{name: 'Central Europe Daylight Time',{name: 'Romance Daylight Time',{name: 'Central European Daylight Time',{name: 'W. Central Africa Daylight Time',{name: 'Namibia Daylight Time',{name: 'Jordan Daylight Time',offset: 2,{name: 'GTB Daylight Time',{name: 'Middle East Daylight Time',{name: 'Egypt Daylight Time',{name: 'Syria Daylight Time',{name: 'E. Europe Daylight Time',{name: 'South Africa Daylight Time',{name: 'FLE Daylight Time',{name: 'Turkey Daylight Time',{name: 'Jerusalem Daylight Time',{name: 'Russia TZ 1 Daylight Time',{name: 'Libya Daylight Time',{name: 'Arabic Daylight Time',offset: 3,{name: 'Arab Daylight Time',{name: 'Belarus Daylight Time',{name: 'Russia TZ 2 Daylight Time',{name: 'E. Africa Daylight Time',{name: 'Iran Daylight Time',offset: 3.5,{name: 'Arabian Daylight Time',offset: 4,{name: 'Azerbaijan Daylight Time',{name: 'Russia TZ 3 Daylight Time',{name: 'Mauritius Daylight Time',{name: 'Georgian Daylight Time',{name: 'Caucasus Daylight Time',{name: 'Afghanistan Daylight Time',offset: 4.5,{name: 'West Asia Daylight Time',offset: 5,{name: 'Russia TZ 4 Daylight Time',{name: 'Pakistan Daylight Time',{name: 'India Daylight Time',offset: 5.5,{name: 'Sri Lanka Daylight Time',{name: 'Nepal Daylight Time',offset: 5.75,{name: 'Central Asia Daylight Time',offset: 6,{name: 'Bangladesh Daylight Time',{name: 'Russia TZ 5 Daylight Time',{name: 'Myanmar Daylight Time',offset: 6.5,{name: 'SE Asia Daylight Time',offset: 7,{name: 'Russia TZ 6 Daylight Time',{name: 'China Daylight Time',offset: 8,{name: 'Russia TZ 7 Daylight Time',{name: 'Malay Peninsula Daylight Time',{name: 'W. Australia Daylight Time',{name: 'Taipei Daylight Time',{name: 'Ulaanbaatar Daylight Time',{name: 'Tokyo Daylight Time',offset: 9,{name: 'Korea Daylight Time',{name: 'Russia TZ 8 Daylight Time',{name: 'Cen. Australia Daylight Time',offset: 9.5,{name: 'AUS Central Daylight Time',{name: 'E. Australia Daylight Time',offset: 10,{name: 'AUS Eastern Daylight Time',{name: 'West Pacific Daylight Time',{name: 'Tasmania Daylight Time',{name: 'Magadan Daylight Time',{name: 'Russia TZ 9 Daylight Time',{name: 'Russia TZ 10 Daylight Time',offset: 11,{name: 'Central Pacific Daylight Time',{name: 'Russia TZ 11 Daylight Time',offset: 12,{name: 'New Zealand Daylight Time',{name: 'UTC+12',{name: 'Fiji Daylight Time',{name: 'Kamchatka Daylight Time',{name: 'Tonga Daylight Time',offset: 13,{name: 'Samoa Daylight Time',{name: 'Line Islands Daylight Time',offset: 14,alt: ''} ]
解决方法
我原来的答案(下面)中描述的功能现在可以在我的TimeZoneConverter .NET库中找到.所有的辛勤工作都是为您完成的,并随着世界时区的变化而不断更新.项目自述文件中的示例显示了如何在Windows,IANA和Rails标识符之间进行转换.
由于问题中描述的应用程序是在Rails中,我建议在.NET中运行后台作业,将Windows时区ID转换为Rails应用程序中所需的ID,并将它们保存在单独的列中.
原始答案
您正在寻找的资源是作为@L_301_2@项目的一部分维护的Windows到IANA映射文件.该文件位于common / supplemental / windowsZones.xml的CLDR版本中,您可以找到它的当前“开发版本”here.
注意以下几点:
>随着新的时区从Microsoft和IANA发布,或者有时政府更改其时区规则以适应不同的映射,文件会更新.
>列表中的偏移量只是标准偏移量 – 也就是夏令时无效时应用的偏移量. “时区”由标准偏移,日光偏移,DST过渡的特定日期和时间以及偏移和过渡的变化历史组成.
> Rails时区名称不应该在Rails之外的任何地方使用.我的理解是它们实际上是在Rails决定使用标准的IANA / Olson时区之前创建的,然后当Ruby tzinfo gem变得可行时,Rails区域通过on this page所示的MAPPING常量进行了改造,然后随着个别投诉的出现而增加了一些区域. .如果可能,只需通过tzinfo gem直接使用IANA时区.如果没有,那么您将有两层映射(Microsoft – > IANA – > Rails).
>我不知道CLDR映射的特定于Rails的实现.我检查了几个CLDR for Rails项目,发现它们没有包含CLDR的特定部分.但是,如果您可以控制Windows方面的内容,那么您可以考虑使用我在in this answer中描述的.NET实现.您可以在Windows端执行Windows到IANA的转换,然后直接使用IANA区域和tzinfo,或者映射到Rails应用程序中的Rails区域.
>还要意识到Rails时区的数量明显少于IANA支持的时区数量.我没有检查过,但有些Windows区域可能会映射到不在Rails中的IANA区域.此外,还有一些Rails区域具有多个Rails条目,但只有一个IANA映射 – 实质上使它们成为等效的别名.
> Rails和Windows都使用“UTC”作为区域ID,Rails映射到“Etc / UTC”,但CLDR映射到“Etc / GMT”.你必须手动处理这个.
>最后,认识到CLDR使用“稳定”标识符的方式与IANA的“规范”标识符不同,这可能会在映射过程中造成一些困难.
>例如,考虑到Microsoft区域“India Standard Time”映射到CLDR中的“Asia / Calcutta”,因为这就是原始IANA区域.但是,IANA将该区域更改为“Asia / Kolkata”,并为“Asia / Calcutta”设置了向后兼容的链接.当您查看Rails MAPPING常量时,有四个Rails区域,“Chennai”,“Kolkata”,“Mumbai”和“New Delhi” – 所有这些区域都映射到“Asia / Kolkata”.
>要解决此问题,您还需要来自CLDR,common/bcp47/timezone.xml
的另一个文件.您可以使用此文件查找别名IANA区域之间的所有链接,这可以帮助您映射回Rails区域.
所以是的,这是可能的 – 但这并不容易.