tz_lookup_wrapper 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8857f1da7ee5eef9c2fa16aaea0756008d52f5cb
4
+ data.tar.gz: cc41ea06e94ab6285e6651e3266dfca575243f43
5
+ SHA512:
6
+ metadata.gz: 6279162bd9827f65eb0108ad832ae27141a43a085c0a324a302937bb03113cf5b7dd97105a133b2223169ef5b3b21d69fff9e9f3543ff500548af47d3772e79f
7
+ data.tar.gz: 35fbf1e9e3322624440d38bab028cc26861291e16ad4c036df205170944ac605c55c3f8643f5c33879d788a31cd4901a30651b022f5356339920f75553dc1254
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/tz-lookup"]
2
+ path = vendor/tz-lookup
3
+ url = https://github.com/darkskyapp/tz-lookup.git
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tz_lookup_wrapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rajitha Perera
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # TzLookupWrapper
2
+
3
+ Ruby gem wrapper for the blazingly fast coordinate to timezone lookup functionality offered by npm package tz-lookup found here : https://github.com/darkskyapp/tz-lookup
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tz_lookup_wrapper', :git => 'https://github.com/rajiteh/tz_lookup_wrapper.git', :branch => 'master', :submodules => true
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tz_lookup_wrapper
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require('tz_lookup_wrapper')
25
+ TzLookupWrapper.lookup(43.7, -79.4) # => "America/Toronto"
26
+ ```
27
+ ## Todo
28
+
29
+ 1. Rewrite the actual tz-lookup library in pure ruby.
30
+ 2. ????
31
+ 3. PROFIT!
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/rajiteh/tz_lookup_wrapper/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,413 @@
1
+ # Extracted from https://github.com/panthomakos/timezone/blob/master/lib/timezone/active_support.rb
2
+ # Copyright (c) 2011 Panayiotis Thomakos
3
+ # https://github.com/panthomakos/timezone/blob/master/License.txt
4
+ module TzLookupWrapper
5
+ # ActiveSupport class for mapping tz info identifiers to rails identifiers
6
+ class ActiveSupport
7
+ TIMEZONE_MAPPING = {
8
+ "Australia/Adelaide" => "Adelaide",
9
+ "Australia/Broken_Hill" => "Adelaide",
10
+ "America/Anchorage" => "Alaska",
11
+ "America/Juneau" => "Alaska",
12
+ "America/Nome" => "Alaska",
13
+ "America/Yakutat" => "Alaska",
14
+ "Pacific/Gambier" => "Alaska",
15
+ "Asia/Almaty" => "Almaty",
16
+ "Europe/Amsterdam" => "Amsterdam",
17
+ "Europe/Athens" => "Athens",
18
+ "America/Anguilla" => "Atlantic Time (Canada)",
19
+ "America/Antigua" => "Atlantic Time (Canada)",
20
+ "America/Argentina/San_Luis" => "Atlantic Time (Canada)",
21
+ "America/Aruba" => "Atlantic Time (Canada)",
22
+ "America/Asuncion" => "Atlantic Time (Canada)",
23
+ "America/Barbados" => "Atlantic Time (Canada)",
24
+ "America/Blanc-Sablon" => "Atlantic Time (Canada)",
25
+ "America/Boa_Vista" => "Atlantic Time (Canada)",
26
+ "America/Campo_Grande" => "Atlantic Time (Canada)",
27
+ "America/Cuiaba" => "Atlantic Time (Canada)",
28
+ "America/Curacao" => "Atlantic Time (Canada)",
29
+ "America/Dominica" => "Atlantic Time (Canada)",
30
+ "America/Eirunepe" => "Atlantic Time (Canada)",
31
+ "America/Glace_Bay" => "Atlantic Time (Canada)",
32
+ "America/Goose_Bay" => "Atlantic Time (Canada)",
33
+ "America/Grenada" => "Atlantic Time (Canada)",
34
+ "America/Guadeloupe" => "Atlantic Time (Canada)",
35
+ "America/Guyana" => "Atlantic Time (Canada)",
36
+ "America/Halifax" => "Atlantic Time (Canada)",
37
+ "America/Manaus" => "Atlantic Time (Canada)",
38
+ "America/Marigot" => "Atlantic Time (Canada)",
39
+ "America/Martinique" => "Atlantic Time (Canada)",
40
+ "America/Moncton" => "Atlantic Time (Canada)",
41
+ "America/Montserrat" => "Atlantic Time (Canada)",
42
+ "America/Porto_Velho" => "Atlantic Time (Canada)",
43
+ "America/Port_of_Spain" => "Atlantic Time (Canada)",
44
+ "America/Puerto_Rico" => "Atlantic Time (Canada)",
45
+ "America/Rio_Branco" => "Atlantic Time (Canada)",
46
+ "America/Santo_Domingo" => "Atlantic Time (Canada)",
47
+ "America/St_Barthelemy" => "Atlantic Time (Canada)",
48
+ "America/St_Kitts" => "Atlantic Time (Canada)",
49
+ "America/St_Lucia" => "Atlantic Time (Canada)",
50
+ "America/St_Thomas" => "Atlantic Time (Canada)",
51
+ "America/St_Vincent" => "Atlantic Time (Canada)",
52
+ "America/Thule" => "Atlantic Time (Canada)",
53
+ "America/Tortola" => "Atlantic Time (Canada)",
54
+ "Antarctica/Palmer" => "Atlantic Time (Canada)",
55
+ "Atlantic/Bermuda" => "Atlantic Time (Canada)",
56
+ "Atlantic/Stanley" => "Atlantic Time (Canada)",
57
+ "Antarctica/McMurdo" => "Auckland",
58
+ "Antarctica/South_Pole" => "Auckland",
59
+ "Pacific/Auckland" => "Auckland",
60
+ "Pacific/Funafuti" => "Auckland",
61
+ "Pacific/Kwajalein" => "Auckland",
62
+ "Pacific/Majuro" => "Auckland",
63
+ "Pacific/Nauru" => "Auckland",
64
+ "Pacific/Tarawa" => "Auckland",
65
+ "Pacific/Wake" => "Auckland",
66
+ "Pacific/Wallis" => "Auckland",
67
+ "Atlantic/Azores" => "Azores",
68
+ "Asia/Baghdad" => "Baghdad",
69
+ "Asia/Baku" => "Baku",
70
+ "Asia/Dubai" => "Baku",
71
+ "Indian/Mahe" => "Baku",
72
+ "Indian/Mauritius" => "Baku",
73
+ "Indian/Reunion" => "Baku",
74
+ "Asia/Bangkok" => "Bangkok",
75
+ "Europe/Belgrade" => "Belgrade",
76
+ "Europe/Berlin" => "Berlin",
77
+ "America/Bogota" => "Bogota",
78
+ "Europe/Bratislava" => "Bratislava",
79
+ "Australia/Brisbane" => "Brisbane",
80
+ "Europe/Brussels" => "Brussels",
81
+ "Europe/Bucharest" => "Bucharest",
82
+ "Europe/Budapest" => "Budapest",
83
+ "America/Araguaina" => "Buenos Aires",
84
+ "America/Argentina/Buenos_Aires" => "Buenos Aires",
85
+ "America/Argentina/Catamarca" => "Buenos Aires",
86
+ "America/Argentina/Cordoba" => "Buenos Aires",
87
+ "America/Argentina/Jujuy" => "Buenos Aires",
88
+ "America/Argentina/La_Rioja" => "Buenos Aires",
89
+ "America/Argentina/Mendoza" => "Buenos Aires",
90
+ "America/Argentina/Rio_Gallegos" => "Buenos Aires",
91
+ "America/Argentina/Salta" => "Buenos Aires",
92
+ "America/Argentina/San_Juan" => "Buenos Aires",
93
+ "America/Argentina/Tucuman" => "Buenos Aires",
94
+ "America/Argentina/Ushuaia" => "Buenos Aires",
95
+ "America/Bahia" => "Buenos Aires",
96
+ "America/Belem" => "Buenos Aires",
97
+ "America/Cayenne" => "Buenos Aires",
98
+ "America/Fortaleza" => "Buenos Aires",
99
+ "America/Godthab" => "Buenos Aires",
100
+ "America/Maceio" => "Buenos Aires",
101
+ "America/Miquelon" => "Buenos Aires",
102
+ "America/Montevideo" => "Buenos Aires",
103
+ "America/Paramaribo" => "Buenos Aires",
104
+ "America/Recife" => "Buenos Aires",
105
+ "America/Santarem" => "Buenos Aires",
106
+ "America/Sao_Paulo" => "Buenos Aires",
107
+ "Antarctica/Rothera" => "Buenos Aires",
108
+ "Africa/Blantyre" => "Cairo",
109
+ "Africa/Bujumbura" => "Cairo",
110
+ "Africa/Cairo" => "Cairo",
111
+ "Africa/Gaborone" => "Cairo",
112
+ "Africa/Johannesburg" => "Cairo",
113
+ "Africa/Kigali" => "Cairo",
114
+ "Africa/Lubumbashi" => "Cairo",
115
+ "Africa/Lusaka" => "Cairo",
116
+ "Africa/Maputo" => "Cairo",
117
+ "Africa/Maseru" => "Cairo",
118
+ "Africa/Mbabane" => "Cairo",
119
+ "Africa/Tripoli" => "Cairo",
120
+ "Asia/Amman" => "Cairo",
121
+ "Asia/Beirut" => "Cairo",
122
+ "Asia/Damascus" => "Cairo",
123
+ "Asia/Gaza" => "Cairo",
124
+ "Asia/Nicosia" => "Cairo",
125
+ "Europe/Chisinau" => "Cairo",
126
+ "Europe/Kaliningrad" => "Cairo",
127
+ "Europe/Kiev" => "Cairo",
128
+ "Europe/Mariehamn" => "Cairo",
129
+ "Europe/Simferopol" => "Cairo",
130
+ "Europe/Uzhgorod" => "Cairo",
131
+ "Europe/Zaporozhye" => "Cairo",
132
+ "America/Scoresbysund" => "Cape Verde Is.",
133
+ "Atlantic/Cape_Verde" => "Cape Verde Is.",
134
+ "America/Caracas" => "Caracas",
135
+ "Africa/Casablanca" => "Casablanca",
136
+ "America/Belize" => "Central Time (US & Canada)",
137
+ "America/Cancun" => "Central Time (US & Canada)",
138
+ "America/Chicago" => "Central Time (US & Canada)",
139
+ "America/Costa_Rica" => "Central Time (US & Canada)",
140
+ "America/El_Salvador" => "Central Time (US & Canada)",
141
+ "America/Guatemala" => "Central Time (US & Canada)",
142
+ "America/Indiana/Knox" => "Central Time (US & Canada)",
143
+ "America/Indiana/Tell_City" => "Central Time (US & Canada)",
144
+ "America/Managua" => "Central Time (US & Canada)",
145
+ "America/Matamoros" => "Central Time (US & Canada)",
146
+ "America/Menominee" => "Central Time (US & Canada)",
147
+ "America/Merida" => "Central Time (US & Canada)",
148
+ "America/North_Dakota/Center" => "Central Time (US & Canada)",
149
+ "America/North_Dakota/New_Salem" => "Central Time (US & Canada)",
150
+ "America/Rainy_River" => "Central Time (US & Canada)",
151
+ "America/Rankin_Inlet" => "Central Time (US & Canada)",
152
+ "America/Regina" => "Central Time (US & Canada)",
153
+ "America/Swift_Current" => "Central Time (US & Canada)",
154
+ "America/Tegucigalpa" => "Central Time (US & Canada)",
155
+ "America/Winnipeg" => "Central Time (US & Canada)",
156
+ "Pacific/Easter" => "Central Time (US & Canada)",
157
+ "Pacific/Galapagos" => "Central Time (US & Canada)",
158
+ "America/Chihuahua" => "Chihuahua",
159
+ "Asia/Chongqing" => "Chongqing",
160
+ "Europe/Copenhagen" => "Copenhagen",
161
+ "Australia/Darwin" => "Darwin",
162
+ "Antarctica/Mawson" => "Dhaka",
163
+ "Asia/Bishkek" => "Dhaka",
164
+ "Asia/Dhaka" => "Dhaka",
165
+ "Asia/Karachi" => "Dhaka",
166
+ "Asia/Novokuznetsk" => "Dhaka",
167
+ "Asia/Omsk" => "Dhaka",
168
+ "Asia/Qyzylorda" => "Dhaka",
169
+ "Asia/Thimphu" => "Dhaka",
170
+ "Indian/Chagos" => "Dhaka",
171
+ "Europe/Dublin" => "Dublin",
172
+ "America/Atikokan" => "Eastern Time (US & Canada)",
173
+ "America/Cayman" => "Eastern Time (US & Canada)",
174
+ "America/Detroit" => "Eastern Time (US & Canada)",
175
+ "America/Grand_Turk" => "Eastern Time (US & Canada)",
176
+ "America/Guayaquil" => "Eastern Time (US & Canada)",
177
+ "America/Havana" => "Eastern Time (US & Canada)",
178
+ "America/Indiana/Indianapolis" => "Eastern Time (US & Canada)",
179
+ "America/Indiana/Marengo" => "Eastern Time (US & Canada)",
180
+ "America/Indiana/Petersburg" => "Eastern Time (US & Canada)",
181
+ "America/Indiana/Vevay" => "Eastern Time (US & Canada)",
182
+ "America/Indiana/Vincennes" => "Eastern Time (US & Canada)",
183
+ "America/Indiana/Winamac" => "Eastern Time (US & Canada)",
184
+ "America/Iqaluit" => "Eastern Time (US & Canada)",
185
+ "America/Jamaica" => "Eastern Time (US & Canada)",
186
+ "America/Kentucky/Louisville" => "Eastern Time (US & Canada)",
187
+ "America/Kentucky/Monticello" => "Eastern Time (US & Canada)",
188
+ "America/Montreal" => "Eastern Time (US & Canada)",
189
+ "America/Nassau" => "Eastern Time (US & Canada)",
190
+ "America/New_York" => "Eastern Time (US & Canada)",
191
+ "America/Nipigon" => "Eastern Time (US & Canada)",
192
+ "America/Panama" => "Eastern Time (US & Canada)",
193
+ "America/Pangnirtung" => "Eastern Time (US & Canada)",
194
+ "America/Port-au-Prince" => "Eastern Time (US & Canada)",
195
+ "America/Resolute" => "Eastern Time (US & Canada)",
196
+ "America/Thunder_Bay" => "Eastern Time (US & Canada)",
197
+ "America/Toronto" => "Eastern Time (US & Canada)",
198
+ "Pacific/Fiji" => "Fiji",
199
+ "Pacific/Guam" => "Guam",
200
+ "Africa/Harare" => "Harare",
201
+ "America/Adak" => "Hawaii",
202
+ "Pacific/Fakaofo" => "Hawaii",
203
+ "Pacific/Honolulu" => "Hawaii",
204
+ "Pacific/Johnston" => "Hawaii",
205
+ "Pacific/Rarotonga" => "Hawaii",
206
+ "Pacific/Tahiti" => "Hawaii",
207
+ "Europe/Helsinki" => "Helsinki",
208
+ "Australia/Hobart" => "Hobart",
209
+ "Antarctica/Casey" => "Hong Kong",
210
+ "Asia/Brunei" => "Hong Kong",
211
+ "Asia/Choibalsan" => "Hong Kong",
212
+ "Asia/Harbin" => "Hong Kong",
213
+ "Asia/Hong_Kong" => "Hong Kong",
214
+ "Asia/Kashgar" => "Hong Kong",
215
+ "Asia/Kuching" => "Hong Kong",
216
+ "Asia/Macau" => "Hong Kong",
217
+ "Asia/Makassar" => "Hong Kong",
218
+ "Asia/Manila" => "Hong Kong",
219
+ "Asia/Shanghai" => "Hong Kong",
220
+ "Asia/Ulaanbaatar" => "Hong Kong",
221
+ "Asia/Irkutsk" => "Irkutsk",
222
+ "Europe/Istanbul" => "Istanbul",
223
+ "Antarctica/Davis" => "Jakarta",
224
+ "Asia/Hovd" => "Jakarta",
225
+ "Asia/Ho_Chi_Minh" => "Jakarta",
226
+ "Asia/Jakarta" => "Jakarta",
227
+ "Asia/Phnom_Penh" => "Jakarta",
228
+ "Asia/Pontianak" => "Jakarta",
229
+ "Asia/Vientiane" => "Jakarta",
230
+ "Indian/Christmas" => "Jakarta",
231
+ "Asia/Jerusalem" => "Jerusalem",
232
+ "Asia/Kabul" => "Kabul",
233
+ "Asia/Kamchatka" => "Kamchatka",
234
+ "Asia/Aqtau" => "Karachi",
235
+ "Asia/Aqtobe" => "Karachi",
236
+ "Asia/Ashgabat" => "Karachi",
237
+ "Asia/Dushanbe" => "Karachi",
238
+ "Asia/Oral" => "Karachi",
239
+ "Asia/Samarkand" => "Karachi",
240
+ "Asia/Yekaterinburg" => "Karachi",
241
+ "Indian/Kerguelen" => "Karachi",
242
+ "Indian/Maldives" => "Karachi",
243
+ "Asia/Kathmandu" => "Kathmandu",
244
+ "Asia/Kolkata" => "Kolkata",
245
+ "Asia/Krasnoyarsk" => "Krasnoyarsk",
246
+ "Asia/Kuala_Lumpur" => "Kuala Lumpur",
247
+ "Asia/Kuwait" => "Kuwait",
248
+ "America/La_Paz" => "La Paz",
249
+ "America/Lima" => "Lima",
250
+ "Europe/Lisbon" => "Lisbon",
251
+ "Europe/Ljubljana" => "Ljubljana",
252
+ "Africa/Abidjan" => "London",
253
+ "Africa/Accra" => "London",
254
+ "Africa/Bamako" => "London",
255
+ "Africa/Banjul" => "London",
256
+ "Africa/Bissau" => "London",
257
+ "Africa/Conakry" => "London",
258
+ "Africa/Dakar" => "London",
259
+ "Africa/El_Aaiun" => "London",
260
+ "Africa/Freetown" => "London",
261
+ "Africa/Lome" => "London",
262
+ "Africa/Nouakchott" => "London",
263
+ "Africa/Ouagadougou" => "London",
264
+ "Africa/Sao_Tome" => "London",
265
+ "America/Danmarkshavn" => "London",
266
+ "Antarctica/Vostok" => "London",
267
+ "Atlantic/Canary" => "London",
268
+ "Atlantic/Faroe" => "London",
269
+ "Atlantic/Madeira" => "London",
270
+ "Atlantic/Reykjavik" => "London",
271
+ "Atlantic/St_Helena" => "London",
272
+ "Europe/Guernsey" => "London",
273
+ "Europe/Isle_of_Man" => "London",
274
+ "Europe/Jersey" => "London",
275
+ "Europe/London" => "London",
276
+ "Europe/Madrid" => "Madrid",
277
+ "Asia/Magadan" => "Magadan",
278
+ "America/Mazatlan" => "Mazatlan",
279
+ "Australia/Melbourne" => "Melbourne",
280
+ "America/Mexico_City" => "Mexico City",
281
+ "America/Noronha" => "Mid-Atlantic",
282
+ "Atlantic/South_Georgia" => "Mid-Atlantic",
283
+ "Europe/Minsk" => "Minsk",
284
+ "Africa/Monrovia" => "Monrovia",
285
+ "America/Monterrey" => "Monterrey",
286
+ "Africa/Addis_Ababa" => "Moscow",
287
+ "Africa/Asmara" => "Moscow",
288
+ "Africa/Dar_es_Salaam" => "Moscow",
289
+ "Africa/Djibouti" => "Moscow",
290
+ "Africa/Kampala" => "Moscow",
291
+ "Africa/Khartoum" => "Moscow",
292
+ "Africa/Mogadishu" => "Moscow",
293
+ "Antarctica/Syowa" => "Moscow",
294
+ "Asia/Aden" => "Moscow",
295
+ "Asia/Bahrain" => "Moscow",
296
+ "Asia/Qatar" => "Moscow",
297
+ "Europe/Moscow" => "Moscow",
298
+ "Europe/Samara" => "Moscow",
299
+ "Indian/Antananarivo" => "Moscow",
300
+ "Indian/Comoro" => "Moscow",
301
+ "Indian/Mayotte" => "Moscow",
302
+ "America/Boise" => "Mountain Time (US & Canada)",
303
+ "America/Cambridge_Bay" => "Mountain Time (US & Canada)",
304
+ "America/Dawson_Creek" => "Mountain Time (US & Canada)",
305
+ "America/Denver" => "Mountain Time (US & Canada)",
306
+ "America/Edmonton" => "Mountain Time (US & Canada)",
307
+ "America/Hermosillo" => "Mountain Time (US & Canada)",
308
+ "America/Inuvik" => "Mountain Time (US & Canada)",
309
+ "America/Ojinaga" => "Mountain Time (US & Canada)",
310
+ "America/Phoenix" => "Mountain Time (US & Canada)",
311
+ "America/Shiprock" => "Mountain Time (US & Canada)",
312
+ "America/Yellowknife" => "Mountain Time (US & Canada)",
313
+ "Asia/Colombo" => "Mumbai",
314
+ "Asia/Muscat" => "Muscat",
315
+ "Africa/Nairobi" => "Nairobi",
316
+ "America/St_Johns" => "Newfoundland",
317
+ "Asia/Novosibirsk" => "Novosibirsk",
318
+ "Pacific/Enderbury" => "Nuku'alofa",
319
+ "Pacific/Tongatapu" => "Nuku'alofa",
320
+ "America/Dawson" => "Pacific Time (US & Canada)",
321
+ "America/Los_Angeles" => "Pacific Time (US & Canada)",
322
+ "America/Santa_Isabel" => "Pacific Time (US & Canada)",
323
+ "America/Vancouver" => "Pacific Time (US & Canada)",
324
+ "America/Whitehorse" => "Pacific Time (US & Canada)",
325
+ "Pacific/Pitcairn" => "Pacific Time (US & Canada)",
326
+ "Africa/Algiers" => "Paris",
327
+ "Africa/Bangui" => "Paris",
328
+ "Africa/Brazzaville" => "Paris",
329
+ "Africa/Ceuta" => "Paris",
330
+ "Africa/Douala" => "Paris",
331
+ "Africa/Kinshasa" => "Paris",
332
+ "Africa/Lagos" => "Paris",
333
+ "Africa/Libreville" => "Paris",
334
+ "Africa/Luanda" => "Paris",
335
+ "Africa/Malabo" => "Paris",
336
+ "Africa/Ndjamena" => "Paris",
337
+ "Africa/Niamey" => "Paris",
338
+ "Africa/Porto-Novo" => "Paris",
339
+ "Africa/Tunis" => "Paris",
340
+ "Africa/Windhoek" => "Paris",
341
+ "Arctic/Longyearbyen" => "Paris",
342
+ "Europe/Andorra" => "Paris",
343
+ "Europe/Gibraltar" => "Paris",
344
+ "Europe/Luxembourg" => "Paris",
345
+ "Europe/Malta" => "Paris",
346
+ "Europe/Monaco" => "Paris",
347
+ "Europe/Oslo" => "Paris",
348
+ "Europe/Paris" => "Paris",
349
+ "Europe/Podgorica" => "Paris",
350
+ "Europe/San_Marino" => "Paris",
351
+ "Europe/Tirane" => "Paris",
352
+ "Europe/Vaduz" => "Paris",
353
+ "Europe/Vatican" => "Paris",
354
+ "Europe/Zurich" => "Paris",
355
+ "Australia/Perth" => "Perth",
356
+ "Pacific/Port_Moresby" => "Port Moresby",
357
+ "Europe/Prague" => "Prague",
358
+ "Asia/Rangoon" => "Rangoon",
359
+ "Indian/Cocos" => "Rangoon",
360
+ "Europe/Riga" => "Riga",
361
+ "Asia/Riyadh" => "Riyadh",
362
+ "Europe/Rome" => "Rome",
363
+ "Pacific/Apia" => "Samoa",
364
+ "Pacific/Midway" => "Samoa",
365
+ "Pacific/Niue" => "Samoa",
366
+ "Pacific/Pago_Pago" => "Samoa",
367
+ "America/Santiago" => "Santiago",
368
+ "Europe/Sarajevo" => "Sarajevo",
369
+ "Asia/Seoul" => "Seoul",
370
+ "Asia/Singapore" => "Singapore",
371
+ "Europe/Skopje" => "Skopje",
372
+ "Europe/Sofia" => "Sofia",
373
+ "Asia/Anadyr" => "Solomon Is.",
374
+ "Pacific/Efate" => "Solomon Is.",
375
+ "Pacific/Guadalcanal" => "Solomon Is.",
376
+ "Pacific/Kosrae" => "Solomon Is.",
377
+ "Pacific/Noumea" => "Solomon Is.",
378
+ "Pacific/Ponape" => "Solomon Is.",
379
+ "Europe/Stockholm" => "Stockholm",
380
+ "Antarctica/DumontDUrville" => "Sydney",
381
+ "Asia/Sakhalin" => "Sydney",
382
+ "Australia/Currie" => "Sydney",
383
+ "Australia/Lindeman" => "Sydney",
384
+ "Australia/Sydney" => "Sydney",
385
+ "Pacific/Saipan" => "Sydney",
386
+ "Pacific/Truk" => "Sydney",
387
+ "Asia/Taipei" => "Taipei",
388
+ "Europe/Tallinn" => "Tallinn",
389
+ "Asia/Tashkent" => "Tashkent",
390
+ "Asia/Tbilisi" => "Tbilisi",
391
+ "Asia/Tehran" => "Tehran",
392
+ "America/Tijuana" => "Tijuana",
393
+ "Asia/Dili" => "Tokyo",
394
+ "Asia/Jayapura" => "Tokyo",
395
+ "Asia/Pyongyang" => "Tokyo",
396
+ "Asia/Tokyo" => "Tokyo",
397
+ "Pacific/Palau" => "Tokyo",
398
+ "Asia/Urumqi" => "Urumqi",
399
+ "Europe/Vienna" => "Vienna",
400
+ "Europe/Vilnius" => "Vilnius",
401
+ "Asia/Vladivostok" => "Vladivostok",
402
+ "Europe/Volgograd" => "Volgograd",
403
+ "Europe/Warsaw" => "Warsaw",
404
+ "Asia/Yakutsk" => "Yakutsk",
405
+ "Asia/Yerevan" => "Yerevan",
406
+ "Europe/Zagreb" => "Zagreb",
407
+ }
408
+
409
+ def self.format(zone)
410
+ TIMEZONE_MAPPING[zone]
411
+ end
412
+ end
413
+ end
@@ -0,0 +1,35 @@
1
+ module TzLookupWrapper
2
+ class DetectNode
3
+ MIN_VER = [0, 10, 0]
4
+
5
+ def self.detect
6
+ node_bins.each do |node|
7
+ detected_version = (`#{node} --version`)[1..-1].split(".") rescue "v0.0.0"
8
+ if detected_version[0].to_i >= MIN_VER[0] and
9
+ detected_version[1].to_i >= MIN_VER[1] and
10
+ detected_version[2].to_i >= MIN_VER[2]
11
+ return node
12
+ end
13
+ end
14
+ raise TzLookupWrapper::NodeOutdatedException.new MIN_VER
15
+ end
16
+
17
+
18
+ private
19
+
20
+ def self.node_bins
21
+ node_binaries = [ 'node', 'nodejs' ]
22
+ detected = []
23
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
24
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
25
+ exts.each { |ext|
26
+ node_binaries.each do |cmd|
27
+ bin = File.join(path, "#{cmd}#{ext}")
28
+ detected << bin if File.executable?(bin) && !File.directory?(bin)
29
+ end
30
+ }
31
+ end
32
+ return detected
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ module TzLookupWrapper
2
+ class BaseTzLookupWrapperException < Exception;end
3
+ class WrapperException < BaseTzLookupWrapperException;end
4
+
5
+ class NodeOutdatedException < BaseTzLookupWrapperException
6
+ def initialize(min_ver)
7
+ super "Cannot find a supported NodeJS installation. Minimum required version (v#{min_ver.join(".") || ""})"
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,3 @@
1
+ module TzLookupWrapper
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,50 @@
1
+ require "tz_lookup_wrapper/version"
2
+ require "tz_lookup_wrapper/active_support"
3
+ require "tz_lookup_wrapper/detect_node"
4
+ require 'tz_lookup_wrapper/exception'
5
+
6
+ module TzLookupWrapper
7
+
8
+ TZ_LOOKUP_PATH="#{File.dirname(__FILE__)}/../vendor/tz-lookup/index.js"
9
+
10
+
11
+ # Lookup a timezone
12
+ #
13
+ # Example:
14
+ # >> TzLookupWrapper.lookup(43.7, -79.4)
15
+ # => "America/Toronto"
16
+ #
17
+ # Arguments:
18
+ # latitude: (Float)
19
+ # longitude: (Float)
20
+
21
+ def self.lookup(lat_r,lng_r)
22
+ lat = Float lat_r
23
+ lng = Float lng_r
24
+ script = <<-HEREDOC
25
+ try {
26
+ process.stdout.write(require("#{TZ_LOOKUP_PATH}")(#{lat}, #{lng}));
27
+ } catch (ex) {
28
+ process.stdout.write(ex.message);
29
+ process.exit(code=1)
30
+ }
31
+ HEREDOC
32
+ result = nil
33
+ IO.popen(node_bin, 'r+') do |io|
34
+ io.puts(script)
35
+ io.close_write
36
+ result = io.gets
37
+ end
38
+ if $?.success?
39
+ result
40
+ else
41
+ raise WrapperException.new result || "Empty output"
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def self.node_bin
48
+ @node_bin ||= TzLookupWrapper::DetectNode.detect
49
+ end
50
+ end