et-orbi 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -0
- data/lib/et-orbi.rb +79 -35
- data/lib/et-orbi/zone_aliases.rb +115 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9087de4253106aad0142d0e3a7985b2fd4cef1f4
|
4
|
+
data.tar.gz: e5b7dc43e253987e3f60b42ce55c4c8b521438d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72c25c33cca74a4e487f215ad9b2b6c1fda170d06387e1bd9242a8b04bc51f2885a0773f11658076d1f3c99b4ddb8e93269028500d991fed82ab5a2f144e6c91
|
7
|
+
data.tar.gz: 220954e56982a997ccee2d2f036f74a10384ab63033055171130cbd984b38c9b1d8148134a57e6db9acb527a35854697e7063a869cb73794d2f529e89a0df7f9
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
# et-orbi CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## et-orbi 1.1.2 released 2018-05-24
|
6
|
+
|
7
|
+
- Let EtOrbi.get_tzone understand "CST+0800"
|
8
|
+
- Introduce EtOrbi.to_windows_tz (Asia/Kolkata to IST-5:30)
|
9
|
+
|
10
|
+
|
5
11
|
## et-orbi 1.1.1 released 2018-05-04
|
6
12
|
|
7
13
|
- Stop caching the local tzone, cache the tools used for determining it
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# et-orbi
|
3
3
|
|
4
4
|
[](http://travis-ci.org/floraison/et-orbi)
|
5
|
+
[](https://ci.appveyor.com/project/jmettraux/et-orbi)
|
5
6
|
[](http://badge.fury.io/rb/et-orbi)
|
6
7
|
|
7
8
|
Time zones for [fugit](https://github.com/floraison/fugit) and for [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler). Urbi et Orbi.
|
data/lib/et-orbi.rb
CHANGED
@@ -4,10 +4,12 @@ require 'time'
|
|
4
4
|
|
5
5
|
require 'tzinfo'
|
6
6
|
|
7
|
+
require 'et-orbi/zone_aliases'
|
8
|
+
|
7
9
|
|
8
10
|
module EtOrbi
|
9
11
|
|
10
|
-
VERSION = '1.1.
|
12
|
+
VERSION = '1.1.2'
|
11
13
|
|
12
14
|
#
|
13
15
|
# module methods
|
@@ -103,7 +105,7 @@ module EtOrbi
|
|
103
105
|
# pass the abbreviation anyway,
|
104
106
|
# it will be used in resulting the error message
|
105
107
|
|
106
|
-
EoTime.new(t
|
108
|
+
EoTime.new(t, z)
|
107
109
|
end
|
108
110
|
|
109
111
|
def make_from_date(d, zone)
|
@@ -151,15 +153,16 @@ module EtOrbi
|
|
151
153
|
|
152
154
|
return nil unless o.is_a?(String)
|
153
155
|
|
154
|
-
|
155
|
-
|
156
|
-
(
|
156
|
+
s = unalias(o)
|
157
|
+
|
158
|
+
get_offset_tzone(s) ||
|
159
|
+
(::TZInfo::Timezone.get(s) rescue nil)
|
157
160
|
end
|
158
161
|
|
159
162
|
def render_nozone_time(seconds)
|
160
163
|
|
161
164
|
t =
|
162
|
-
Time.utc(
|
165
|
+
Time.utc(1970) + seconds
|
163
166
|
ts =
|
164
167
|
t.strftime('%Y-%m-%d %H:%M:%S') +
|
165
168
|
".#{(seconds % 1).to_s.split('.').last}"
|
@@ -175,22 +178,26 @@ module EtOrbi
|
|
175
178
|
|
176
179
|
etos = Proc.new { |k, v| "#{k}:#{v.inspect}" }
|
177
180
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
181
|
+
h = {
|
182
|
+
'etz' => ENV['TZ'],
|
183
|
+
'tnz' => Time.now.zone,
|
184
|
+
'tzid' => defined?(TZInfo::Data),
|
185
|
+
'rv' => RUBY_VERSION,
|
186
|
+
'rp' => RUBY_PLATFORM,
|
187
|
+
'win' => Gem.win_platform?,
|
188
|
+
'rorv' => (Rails::VERSION::STRING rescue nil),
|
189
|
+
'astz' => ([ Time.zone.class, Time.zone.tzinfo.name ] rescue nil),
|
190
|
+
'eov' => EtOrbi::VERSION,
|
191
|
+
'eotnz' => '???',
|
192
|
+
'eotnfz' => '???',
|
193
|
+
'eotlzn' => '???' }
|
194
|
+
if ltz = EtOrbi::EoTime.local_tzone
|
195
|
+
h['eotnz'] = EtOrbi::EoTime.now.zone
|
196
|
+
h['eotnfz'] = EtOrbi::EoTime.now.strftime('%z')
|
197
|
+
h['eotlzn'] = ltz.name
|
198
|
+
end
|
199
|
+
|
200
|
+
"(#{h.map(&etos).join(',')},#{gather_tzs.map(&etos).join(',')})"
|
194
201
|
end
|
195
202
|
|
196
203
|
alias make make_time
|
@@ -301,7 +308,7 @@ module EtOrbi
|
|
301
308
|
|
302
309
|
fail ArgumentError.new(
|
303
310
|
"Cannot determine timezone from #{zone.inspect}" +
|
304
|
-
"\n#{EtOrbi.render_nozone_time(
|
311
|
+
"\n#{EtOrbi.render_nozone_time(@seconds)}" +
|
305
312
|
"\n#{EtOrbi.platform_info.sub(',debian:', ",\ndebian:")}" +
|
306
313
|
"\nTry setting `ENV['TZ'] = 'Continent/City'` in your script " +
|
307
314
|
"(see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)" +
|
@@ -328,7 +335,7 @@ module EtOrbi
|
|
328
335
|
#
|
329
336
|
def utc
|
330
337
|
|
331
|
-
Time.utc(1970
|
338
|
+
Time.utc(1970) + @seconds
|
332
339
|
end
|
333
340
|
|
334
341
|
# Returns true if this ::EtOrbi::EoTime instance timezone is UTC.
|
@@ -336,7 +343,8 @@ module EtOrbi
|
|
336
343
|
#
|
337
344
|
def utc?
|
338
345
|
|
339
|
-
%w[
|
346
|
+
%w[ gmt utc zulu etc/gmt etc/utc ].include?(
|
347
|
+
@zone.canonical_identifier.downcase)
|
340
348
|
end
|
341
349
|
|
342
350
|
alias getutc utc
|
@@ -616,7 +624,7 @@ module EtOrbi
|
|
616
624
|
|
617
625
|
etz = ENV['TZ']
|
618
626
|
|
619
|
-
tz = ::TZInfo::Timezone.get(etz) rescue nil
|
627
|
+
tz = etz && (::TZInfo::Timezone.get(etz) rescue nil)
|
620
628
|
return tz if tz
|
621
629
|
|
622
630
|
if Time.respond_to?(:zone) && Time.zone.respond_to?(:tzinfo)
|
@@ -628,14 +636,44 @@ module EtOrbi
|
|
628
636
|
return tz if tz
|
629
637
|
|
630
638
|
tzs = determine_local_tzones
|
631
|
-
(etz && tzs.find { |z| z.name == etz }) || tzs.first
|
639
|
+
tz = (etz && tzs.find { |z| z.name == etz }) || tzs.first
|
640
|
+
return tz if tz
|
641
|
+
|
642
|
+
n = Time.now
|
643
|
+
|
644
|
+
get_tzone(n.zone) ||
|
645
|
+
get_tzone(n.strftime('%Z%z'))
|
632
646
|
end
|
633
647
|
|
648
|
+
attr_accessor :_os_zone # test tool
|
649
|
+
|
634
650
|
def os_tz
|
635
651
|
|
652
|
+
return (@_os_zone == '' ? nil : @_os_zone) if @_os_zone
|
653
|
+
|
636
654
|
@os_tz ||= (debian_tz || centos_tz || osx_tz)
|
637
655
|
end
|
638
656
|
|
657
|
+
def to_windows_tz(zone_name, time=Time.now)
|
658
|
+
|
659
|
+
twin = Time.utc(time.year, 1, 1) # winter
|
660
|
+
tsum = Time.utc(time.year, 7, 1) # summer
|
661
|
+
|
662
|
+
tz = ::TZInfo::Timezone.get(zone_name)
|
663
|
+
tzo = tz.period_for_local(time).utc_total_offset
|
664
|
+
tzop = tzo < 0 ? nil : '-'; tzo = tzo.abs
|
665
|
+
tzoh = tzo / 3600
|
666
|
+
tzos = tzo % 3600
|
667
|
+
tzos = tzos == 0 ? nil : ':%02d' % (tzos / 60)
|
668
|
+
|
669
|
+
abbs = [
|
670
|
+
tz.period_for_utc(twin).abbreviation.to_s,
|
671
|
+
tz.period_for_utc(tsum).abbreviation.to_s ]
|
672
|
+
.uniq
|
673
|
+
|
674
|
+
[ abbs[0], tzop, tzoh, tzos, abbs[1] ].compact.join
|
675
|
+
end
|
676
|
+
|
639
677
|
#
|
640
678
|
# protected module methods
|
641
679
|
|
@@ -664,7 +702,8 @@ module EtOrbi
|
|
664
702
|
mn = -mn if hr && hr < 0
|
665
703
|
|
666
704
|
return (
|
667
|
-
@custom_tz_cache[str] =
|
705
|
+
(@custom_tz_cache ||= {})[str] =
|
706
|
+
create_offset_tzone(hr * 3600 + mn * 60, str)
|
668
707
|
) if hr
|
669
708
|
|
670
709
|
nil
|
@@ -694,7 +733,9 @@ module EtOrbi
|
|
694
733
|
def determine_local_tzones
|
695
734
|
|
696
735
|
tabbs = (-6..5)
|
697
|
-
.collect { |i|
|
736
|
+
.collect { |i|
|
737
|
+
t = Time.now + i * 30 * 24 * 3600
|
738
|
+
"#{t.zone}_#{t.utc_offset}" }
|
698
739
|
.uniq
|
699
740
|
.sort
|
700
741
|
.join('|')
|
@@ -702,19 +743,22 @@ module EtOrbi
|
|
702
743
|
t = Time.now
|
703
744
|
#tu = t.dup.utc # /!\ dup is necessary, #utc modifies its target
|
704
745
|
|
705
|
-
twin = Time.
|
706
|
-
tsum = Time.
|
746
|
+
twin = Time.local(t.year, 1, 1) # winter
|
747
|
+
tsum = Time.local(t.year, 7, 1) # summer
|
707
748
|
|
708
749
|
@tz_all ||= ::TZInfo::Timezone.all
|
709
750
|
@tz_winter_summer ||= {}
|
710
751
|
|
711
752
|
@tz_winter_summer[tabbs] ||= @tz_all
|
712
753
|
.select { |tz|
|
754
|
+
pw = tz.period_for_local(twin)
|
755
|
+
ps = tz.period_for_local(tsum)
|
713
756
|
tabbs ==
|
714
|
-
[
|
715
|
-
|
716
|
-
|
717
|
-
|
757
|
+
[ "#{pw.abbreviation}_#{pw.utc_total_offset}",
|
758
|
+
"#{ps.abbreviation}_#{ps.utc_total_offset}" ]
|
759
|
+
.uniq.sort.join('|') }
|
760
|
+
|
761
|
+
@tz_winter_summer[tabbs]
|
718
762
|
end
|
719
763
|
|
720
764
|
#
|
@@ -0,0 +1,115 @@
|
|
1
|
+
|
2
|
+
module EtOrbi
|
3
|
+
|
4
|
+
def self.unalias(name)
|
5
|
+
|
6
|
+
ZONE_ALIASES[name.sub(/ Daylight /, ' Standard ')] ||
|
7
|
+
unzz(name) ||
|
8
|
+
name
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.unzz(name)
|
12
|
+
|
13
|
+
m = name.match(/\A([A-Z]{3,4})([+-])(\d{1,2}):?(\d{2})?\z/)
|
14
|
+
return nil unless m
|
15
|
+
|
16
|
+
abbs = [ m[1] ]; a = m[1]
|
17
|
+
abbs << "#{a}T" if a.size < 4
|
18
|
+
|
19
|
+
off = (m[2] == '+' ? 1 : -1) * (m[3].to_i * 3600 + (m[4] || '0').to_i * 60)
|
20
|
+
|
21
|
+
t = Time.now
|
22
|
+
twin = Time.utc(t.year, 1, 1) # winter
|
23
|
+
tsum = Time.utc(t.year, 7, 1) # summer
|
24
|
+
|
25
|
+
(@tz_all ||= ::TZInfo::Timezone.all)
|
26
|
+
.each { |tz|
|
27
|
+
abbs.each { |abb|
|
28
|
+
per = tz.period_for_utc(twin)
|
29
|
+
return tz.name \
|
30
|
+
if per.abbreviation.to_s == abb && per.utc_total_offset == off
|
31
|
+
per = tz.period_for_utc(tsum)
|
32
|
+
return tz.name \
|
33
|
+
if per.abbreviation.to_s == abb && per.utc_total_offset == off } }
|
34
|
+
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
ZONE_ALIASES = {
|
39
|
+
'Coordinated Universal Time' => 'UTC',
|
40
|
+
'Afghanistan Standard Time' => 'Asia/Kabul',
|
41
|
+
'FLE Standard Time' => 'Europe/Helsinki',
|
42
|
+
'Central Europe Standard Time' => 'Europe/Prague',
|
43
|
+
'UTC-11' => 'Etc/GMT+11',
|
44
|
+
'W. Europe Standard Time' => 'Europe/Rome',
|
45
|
+
'W. Central Africa Standard Time' => 'Africa/Lagos',
|
46
|
+
'SA Western Standard Time' => 'America/La_Paz',
|
47
|
+
'Pacific SA Standard Time' => 'America/Santiago',
|
48
|
+
'Argentina Standard Time' => 'America/Argentina/Buenos_Aires',
|
49
|
+
'Caucasus Standard Time' => 'Asia/Yerevan',
|
50
|
+
'AUS Eastern Standard Time' => 'Australia/Sydney',
|
51
|
+
'Azerbaijan Standard Time' => 'Asia/Baku',
|
52
|
+
'Eastern Standard Time' => 'America/New_York',
|
53
|
+
'Arab Standard Time' => 'Asia/Riyadh',
|
54
|
+
'Bangladesh Standard Time' => 'Asia/Dhaka',
|
55
|
+
'Belarus Standard Time' => 'Europe/Minsk',
|
56
|
+
'Romance Standard Time' => 'Europe/Paris',
|
57
|
+
'Central America Standard Time' => 'America/Belize',
|
58
|
+
'Atlantic Standard Time' => 'Atlantic/Bermuda',
|
59
|
+
'Venezuela Standard Time' => 'America/Caracas',
|
60
|
+
'Central European Standard Time' => 'Europe/Warsaw',
|
61
|
+
'South Africa Standard Time' => 'Africa/Johannesburg',
|
62
|
+
#'UTC' => 'Etc/UTC', # 'UTC' is good as is
|
63
|
+
'E. South America Standard Time' => 'America/Sao_Paulo',
|
64
|
+
'Central Asia Standard Time' => 'Asia/Almaty',
|
65
|
+
'Singapore Standard Time' => 'Asia/Singapore',
|
66
|
+
'Greenwich Standard Time' => 'Africa/Monrovia',
|
67
|
+
'Cape Verde Standard Time' => 'Atlantic/Cape_Verde',
|
68
|
+
'SE Asia Standard Time' => 'Asia/Bangkok',
|
69
|
+
'SA Pacific Standard Time' => 'America/Bogota',
|
70
|
+
'China Standard Time' => 'Asia/Shanghai',
|
71
|
+
'Myanmar Standard Time' => 'Asia/Yangon',
|
72
|
+
'E. Africa Standard Time' => 'Africa/Nairobi',
|
73
|
+
'Hawaiian Standard Time' => 'Pacific/Honololu',
|
74
|
+
'E. Europe Standard Time' => 'Europe/Nicosia',
|
75
|
+
'Tokyo Standard Time' => 'Asia/Tokyo',
|
76
|
+
'Egypt Standard Time' => 'Africa/Cairo',
|
77
|
+
'SA Eastern Standard Time' => 'America/Cayenne',
|
78
|
+
'GMT Standard Time' => 'Europe/London',
|
79
|
+
'Fiji Standard Time' => 'Pacific/Fiji',
|
80
|
+
'West Asia Standard Time' => 'Asia/Tashkent',
|
81
|
+
'Georgian Standard Time' => 'Asia/Tbilisi',
|
82
|
+
'GTB Standard Time' => 'Europe/Athens',
|
83
|
+
'Greenland Standard Time' => 'America/Godthab',
|
84
|
+
'West Pacific Standard Time' => 'Pacific/Guam',
|
85
|
+
'Mauritius Standard Time' => 'Indian/Mauritius',
|
86
|
+
'India Standard Time' => 'Asia/Kolkata',
|
87
|
+
'Iran Standard Time' => 'Asia/Tehran',
|
88
|
+
'Arabic Standard Time' => 'Asia/Baghdad',
|
89
|
+
'Israel Standard Time' => 'Asia/Jerusalem',
|
90
|
+
'Jordan Standard Time' => 'Asia/Amman',
|
91
|
+
'UTC+12' => 'Etc/GMT-12',
|
92
|
+
'Korea Standard Time' => 'Asia/Seoul',
|
93
|
+
'Middle East Standard Time' => 'Asia/Beirut',
|
94
|
+
'Central Standard Time (Mexico)' => 'America/Mexico_City',
|
95
|
+
'Ulaanbaatar Standard Time' => 'Asia/Ulaanbaatar',
|
96
|
+
'Morocco Standard Time' => 'Africa/Casablanca',
|
97
|
+
'Namibia Standard Time' => 'Africa/Windhoek',
|
98
|
+
'Nepal Standard Time' => 'Asia/Kathmandu',
|
99
|
+
'Central Pacific Standard Time' => 'Etc/GMT-11',
|
100
|
+
'New Zealand Standard Time' => 'Pacific/Auckland',
|
101
|
+
'Arabian Standard Time' => 'Asia/Dubai',
|
102
|
+
'Pakistan Standard Time' => 'Asia/Karachi',
|
103
|
+
'Paraguay Standard Time' => 'America/Asuncion',
|
104
|
+
'Pacific Standard Time' => 'America/Los_Angeles',
|
105
|
+
'Russian Standard Time' => 'Europe/Moscow',
|
106
|
+
'Samoa Standard Time' => 'Pacific/Pago_Pago',
|
107
|
+
'UTC-02' => 'Etc/GMT+2',
|
108
|
+
'Sri Lanka Standard Time' => 'Asia/Kolkata',
|
109
|
+
'Syria Standard Time' => 'Asia/Damascus',
|
110
|
+
'Taipei Standard Time' => 'Asia/Taipei',
|
111
|
+
'Tonga Standard Time' => 'Pacific/Tongatapu',
|
112
|
+
'Turkey Standard Time' => 'Asia/Istanbul',
|
113
|
+
'Montevideo Standard Time' => 'America/Montevideo' }
|
114
|
+
end
|
115
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: et-orbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- et-orbi.gemspec
|
54
54
|
- lib/et-orbi.rb
|
55
|
+
- lib/et-orbi/zone_aliases.rb
|
55
56
|
- lib/et_orbi.rb
|
56
57
|
- lib/etorbi.rb
|
57
58
|
homepage: http://github.com/floraison/et-orbi
|