ruby-changes:58534
From: Jeremy <ko1@a...>
Date: Fri, 1 Nov 2019 17:30:52 +0900 (JST)
Subject: [ruby-changes:58534] 469545307f (master): [ruby/date] Add more timezone abbreviations
https://git.ruby-lang.org/ruby.git/commit/?id=469545307f From 469545307f7b688d0b7a15a5cfd33bcecb775123 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Thu, 31 Oct 2019 11:29:37 -0700 Subject: [ruby/date] Add more timezone abbreviations This gets the time zone abbreviations from https://www.timeanddate.com/time/zones/, and adds unambiguous time zones not already present in zonetab.list. See bin/update-abbr for the program used. This regenerates zonetab.h using prereq.mk (requires gperf). Only one test line is added, just to make sure a new time zone abbreviation is picked up. Fixes Ruby Bug 16286 https://github.com/ruby/date/commit/702e8b3033 diff --git a/bin/update-abbr b/bin/update-abbr new file mode 100644 index 0000000..33dbda1 --- /dev/null +++ b/bin/update-abbr @@ -0,0 +1,35 @@ https://github.com/ruby/ruby/blob/trunk/bin/update-abbr#L1 +require 'nokogiri' +require 'open-uri' + +doc = Nokogiri::HTML(URI.open('https://www.timeanddate.com/time/zones/')) + +h = {} + +doc.css('#tz-abb tbody tr').each do |tr| + tds = tr.css('td') + abbr = tds[0].text.strip.downcase + offset = tds[3].text.strip.gsub(/UTC\s*/, '') + next if offset.include?('/') # skip ambiguous timezones + next if offset.empty? + + + hour, min = offset.split(':', 2) + offset = (Integer(hour) * 60 + (Integer(min || 0)))*60 + if h.has_key?(abbr) + h[abbr] = false + else + h[abbr] = offset + end +end + +h.delete_if{|_,v| !v} + +lines = File.readlines('ext/date/zonetab.list') +lines.select{|l| l.include?(',')}. + map{|l| l.split(',', 2)[0]}. + each{|a| h.delete(a)} + +h.sort.map{|k,v| "#{k},#{v}"} +lines.insert(-2, h.sort.map{|k,v| "#{k},#{v}\n"}) +lines.flatten! +File.write('ext/date/zonetab.list', lines.join) diff --git a/ext/date/zonetab.h b/ext/date/zonetab.h index 37df5b9..379f78e 100644 --- a/ext/date/zonetab.h +++ b/ext/date/zonetab.h @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/date/zonetab.h#L1 /* ANSI-C code produced by gperf version 3.1 */ /* Command-line: gperf --ignore-case -C -c -P -p -j1 -i 1 -g -o -t -N zonetab zonetab.list */ -/* Computed positions: -k'1-4,$' */ +/* Computed positions: -k'1-4,9' */ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ @@ -40,12 +40,12 @@ static const struct zone *zonetab(); https://github.com/ruby/ruby/blob/trunk/ext/date/zonetab.h#L40 #line 9 "zonetab.list" struct zone; -#define TOTAL_KEYWORDS 170 +#define TOTAL_KEYWORDS 316 #define MIN_WORD_LENGTH 1 #define MAX_WORD_LENGTH 17 -#define MIN_HASH_VALUE 5 -#define MAX_HASH_VALUE 438 -/* maximum key range = 434, duplicates = 0 */ +#define MIN_HASH_VALUE 2 +#define MAX_HASH_VALUE 619 +/* maximum key range = 618, duplicates = 0 */ #ifndef GPERF_DOWNCASE #define GPERF_DOWNCASE 1 @@ -104,398 +104,702 @@ hash (register const char *str, register size_t len) https://github.com/ruby/ruby/blob/trunk/ext/date/zonetab.h#L104 { static const unsigned short asso_values[] = { - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 19, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 2, 4, 439, 439, 439, - 439, 439, 8, 6, 3, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 7, 63, 53, 2, 4, - 32, 110, 88, 78, 90, 68, 47, 108, 10, 73, - 81, 124, 3, 1, 4, 77, 116, 88, 15, 96, - 45, 5, 439, 439, 439, 439, 439, 7, 63, 53, - 2, 4, 32, 110, 88, 78, 90, 68, 47, 108, - 10, 73, 81, 124, 3, 1, 4, 77, 116, 88, - 15, 96, 45, 5, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439, 439, 439, 439, - 439, 439, 439, 439, 439, 439, 439 + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 17, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 3, 2, 620, 620, 620, + 620, 620, 70, 8, 3, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 39, 176, 207, 70, 168, + 1, 5, 18, 74, 218, 2, 117, 130, 48, 88, + 125, 225, 92, 1, 1, 12, 54, 30, 36, 13, + 48, 168, 263, 59, 114, 166, 109, 39, 176, 207, + 70, 168, 1, 5, 18, 74, 218, 2, 117, 130, + 48, 88, 125, 225, 92, 1, 1, 12, 54, 30, + 36, 13, 48, 168, 263, 59, 114, 166, 109, 27, + 104, 1, 9, 4, 309, 190, 188, 177, 255, 108, + 2, 341, 3, 620, 620, 620, 620, 620, 620, 12, + 54, 30, 36, 13, 48, 168, 263, 59, 114, 166, + 109, 27, 104, 1, 9, 4, 309, 190, 188, 177, + 255, 108, 2, 341, 3, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620, 620, 620, + 620, 620, 620, 620, 620, 620, 620, 620 }; register unsigned int hval = (unsigned int)len; switch (hval) { default: + hval += asso_values[(unsigned char)str[8]]; + /*FALLTHROUGH*/ + case 8: + case 7: + case 6: + case 5: + case 4: hval += asso_values[(unsigned char)str[3]]; /*FALLTHROUGH*/ case 3: hval += asso_values[(unsigned char)str[2]]; /*FALLTHROUGH*/ case 2: - hval += asso_values[(unsigned char)str[1]]; + hval += asso_values[(unsigned char)str[1]+6]; /*FALLTHROUGH*/ case 1: - hval += asso_values[(unsigned char)str[0]+1]; + hval += asso_values[(unsigned char)str[0]+52]; break; } - return (unsigned int)hval + asso_values[(unsigned char)str[len - 1]]; + return (unsigned int)hval; } struct stringpool_t { - char stringpool_str5[sizeof("r")]; - char stringpool_str6[sizeof("s")]; - char stringpool_str7[sizeof("d")]; - char stringpool_str14[sizeof("cst")]; - char stringpool_str15[sizeof("cdt")]; - char stringpool_str16[sizeof("sst")]; - char stringpool_str17[sizeof("cet")]; - char stringpool_str18[sizeof("msd")]; - char stringpool_str19[sizeof("cest")]; - char stringpool_str20[sizeof("cat")]; - char stringpool_str22[sizeof("mst")]; - char stringpool_str23[sizeof("mdt")]; - char stringpool_str24[sizeof("sast")]; - char stringpool_str25[sizeof("met")]; - char stringpool_str27[sizeof("mest")]; - char stringpool_str30[sizeof("wet")]; - char stringpool_str31[sizeof("dateline")]; - char stringpool_str32[sizeof("west")]; - char stringpool_str33[sizeof("wat")]; - char stringpool_str35[sizeof("wast")]; - char stringpool_str36[sizeof("wadt")]; - char stringpool_str37[sizeof("e")]; - char stringpool_str38[sizeof("central europe")]; - char stringpool_str39[sizeof("central asia")]; - char stringpool_str40[sizeof("west asia")]; - char stringpool_str41[sizeof("cen. australia")]; - char stringpool_str42[sizeof("central america")]; - char stringpool_str44[sizeof("est")]; - char stringpool_str45[sizeof("edt")]; - char stringpool_str46[sizeof("central european")]; - char stringpool_str47[sizeof("eet")]; - char stringpool_str48[sizeof("se asia")]; - char stringpool_str49[sizeof("eest")]; - char stringpool_str50[sizeof("eat")]; - char stringpool_str51[sizeof("z")]; - char stringpool_str52[sizeof("east")]; - char stringpool_str53[sizeof("eadt")]; - char stringpool_str54[sizeof("sa eastern")]; - char stringpool_str55[sizeof("w. europe")]; - char stringpool_str56[sizeof("c")]; - char stringpool_str57[sizeof("yst")]; - char stringpool_str58[sizeof("ydt")]; - char stringpool_str59[sizeof("kst")]; - char stringpool_str60[sizeof("clt")]; - char stringpool_str61[sizeof("eastern")]; - char stringpool_str62[sizeof("clst")]; - char stringpool_str63[sizeof("bt")]; - char stringpool_str64[sizeof("w. australia")]; - char stringpool_str65[sizeof("bst")]; - char stringpool_str66[sizeof("cct")]; - char stringpool_str67[sizeof("brt")]; - char stringpool_str69[sizeof("brst")]; - char stringpool_str71[sizeof("a")]; - char stringpool_str72[sizeof("e. europe")]; - char stringpool_str73[sizeof("at")]; - char stringpool_str74[sizeof("central")]; - char stringpool_str75[sizeof("ast")]; - char stringpool_str76[sizeof("adt")]; - char stringpool_str77[sizeof("art")]; - char stringpool_str78[sizeof("e. africa")]; - char stringpool_str79[sizeof("e. south america")]; - char stringpool_str80[sizeof("jst")]; - char stringpool_str81[sizeof("e. australia")]; - char stringpool_str82[sizeof("t")]; - char stringpool_str83[sizeof("nt")]; - char stringpool_str84[ (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/