1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/date] Honor timezones from timeanddate.com

https://github.com/ruby/date/commit/d20380fc55
This commit is contained in:
Nobuyoshi Nakada 2020-09-29 23:52:51 +09:00 committed by Hiroshi SHIBATA
parent d65f1140b9
commit 81dece54d6

View file

@ -2,7 +2,7 @@
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(URI.open('https://www.timeanddate.com/time/zones/'))
doc = Nokogiri::HTML(URI.open(ARGV[0] || 'https://www.timeanddate.com/time/zones/'))
h = {}
@ -26,9 +26,26 @@ end
h.delete_if{|_,v| !v}
lines = File.readlines('zonetab.list')
lines.select{|l| l.include?(',')}.
map{|l| l.split(',', 2)[0]}.
each{|a| h.delete(a)}
lines.map! do |l|
if (sep = /^%%/ =~ l)...(sep = /^%%/ =~ l) and !sep
z, o = l.split(/,\s*/, 2)
o.strip!
if ho = h.delete(z) and ho != eval(o)
warn "offset of #{z}: #{o} -> #{ho}"
l = l.sub(/,\s*\K.*/) {
if o.include?("*")
o1, o2 = ho.abs.divmod(3600)
o1 = "#{o1}*3600"
o1 = "(#{o1}+#{o2})" if o2 != 0
ho < 0 ? "-#{o1}" : o1
else
ho.to_s
end
}
end
end
l
end
lines.insert(-2, h.sort.map{|k,v| "#{k},#{v}\n"})
lines.flatten!