et-orbi 1.0.5 → 1.0.6
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 +8 -0
- data/CREDITS.md +3 -1
- data/Makefile +16 -2
- data/README.md +10 -0
- data/et-orbi.gemspec +3 -1
- data/lib/et-orbi.rb +110 -50
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16693871e0e1a8330e6ecade907b21302ad124ab
|
4
|
+
data.tar.gz: 00fee3dbf2143ee21043597a1d64f7d19c2c6dfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f151d68c6c1f070945f9cf9718e7d38004117832b53acac741de0e5e2c38ec8cd06c4bccca60a93072bc1b7dad2342a6e5bac7ed17f2a8829ec47554e36e0be
|
7
|
+
data.tar.gz: 66af905287bb713bc376adb0e67b7c1eac19a486fbc4a93c902615f33280dad69586f245726e3fb19a57ac6ab5649a7737391d3b1ead3d13b7aef6a945f96e65
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
# et-orbi CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## et-orbi 1.0.6 released 2017-10-05
|
6
|
+
|
7
|
+
- Introduce `make info`
|
8
|
+
- Alias EoTime#to_utc_time to #utc
|
9
|
+
- Alias EoTime#to_t to #to_local_time
|
10
|
+
- Implement EoTime#to_local_time (since #to_time returns a UTC Time instance)
|
11
|
+
|
12
|
+
|
5
13
|
## et-orbi 1.0.5 released 2017-06-23
|
6
14
|
|
7
15
|
- Rework EtOrbi.make_time
|
data/CREDITS.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
|
2
2
|
# et-orbi credits
|
3
3
|
|
4
|
-
*
|
4
|
+
* Chris Arcand https://github.com/chrisarcand shew various issues around America/Chicago on OSX, gh-4
|
5
|
+
* Jeremy Strouse https://github.com/jstrouse helped alleviate issue with older versions of TZInfo
|
6
|
+
|
5
7
|
|
6
8
|
## since rufus-scheduler
|
7
9
|
|
data/Makefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
##
|
2
|
+
## core floraison make ##
|
3
3
|
|
4
4
|
NAME = \
|
5
5
|
$(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
|
@@ -26,6 +26,20 @@ build: gemspec_validate
|
|
26
26
|
push: build
|
27
27
|
gem push pkg/$(NAME)-$(VERSION).gem
|
28
28
|
|
29
|
+
spec:
|
30
|
+
bundle exec rspec
|
31
|
+
test: spec
|
29
32
|
|
30
|
-
|
33
|
+
|
34
|
+
## specific to project ##
|
35
|
+
|
36
|
+
info:
|
37
|
+
uname -a
|
38
|
+
bundle exec ruby -v
|
39
|
+
bundle exec ruby -Ilib -r et-orbi -e "EtOrbi._make_info"
|
40
|
+
|
41
|
+
|
42
|
+
## done ##
|
43
|
+
|
44
|
+
.PHONY: build info push spec
|
31
45
|
|
data/README.md
CHANGED
@@ -28,6 +28,16 @@ EtOrbi::EoTime.new(0, 'Europe/Moscow').to_s
|
|
28
28
|
# => "1970-01-01 03:00:00 +0300"
|
29
29
|
```
|
30
30
|
|
31
|
+
More about `EtOrbi::EoTime` instances:
|
32
|
+
```
|
33
|
+
eot = EtOrbi::EoTime.new(0, 'Europe/Moscow')
|
34
|
+
|
35
|
+
eot.to_local_time.class # => Time
|
36
|
+
eot.to_local_time.to_s # => "1970-01-01 09:00:00 +0900" (at least on my system)
|
37
|
+
|
38
|
+
# For the rest, EtOrbi::EoTime mimicks ::Time
|
39
|
+
```
|
40
|
+
|
31
41
|
Helper methods:
|
32
42
|
```ruby
|
33
43
|
require 'et-orbi'
|
data/et-orbi.gemspec
CHANGED
@@ -20,9 +20,11 @@ Time zones for fugit and rufus-scheduler. Urbi et Orbi.
|
|
20
20
|
|
21
21
|
#s.files = `git ls-files`.split("\n")
|
22
22
|
s.files = Dir[
|
23
|
+
'README.{md,txt}',
|
24
|
+
'CHANGELOG.{md,txt}', 'CREDITS.{md,txt}', 'LICENSE.{md,txt}',
|
23
25
|
'Makefile',
|
24
26
|
'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
|
25
|
-
|
27
|
+
"#{s.name}.gemspec",
|
26
28
|
]
|
27
29
|
|
28
30
|
s.add_runtime_dependency 'tzinfo'
|
data/lib/et-orbi.rb
CHANGED
@@ -7,7 +7,7 @@ require 'tzinfo'
|
|
7
7
|
|
8
8
|
module EtOrbi
|
9
9
|
|
10
|
-
VERSION = '1.0.
|
10
|
+
VERSION = '1.0.6'
|
11
11
|
|
12
12
|
#
|
13
13
|
# module methods
|
@@ -36,12 +36,19 @@ module EtOrbi
|
|
36
36
|
# is necessary since Time.parse('xxx') in Ruby < 1.9 yields `now`
|
37
37
|
|
38
38
|
str_zone = get_tzone(list_iso8601_zones(str).last)
|
39
|
+
#p [ :parse, str, str_zone ]
|
40
|
+
#p ENV['TZ']
|
39
41
|
|
42
|
+
#p [ :parse, :oz, opts[:zone] ]
|
43
|
+
#p [ :parse, :sz, str_zone ]
|
44
|
+
#p [ :parse, :foz, find_olson_zone(str) ]
|
45
|
+
#p [ :parse, :ltz, local_tzone ]
|
40
46
|
zone =
|
41
47
|
opts[:zone] ||
|
42
48
|
str_zone ||
|
43
49
|
find_olson_zone(str) ||
|
44
50
|
local_tzone
|
51
|
+
#p [ :parse, :zone, zone ]
|
45
52
|
|
46
53
|
str = str.sub(zone.name, '') unless zone.name.match(/\A[-+]/)
|
47
54
|
#
|
@@ -49,6 +56,7 @@ module EtOrbi
|
|
49
56
|
# although where does rufus-scheduler have it from?
|
50
57
|
|
51
58
|
local = Time.parse(str)
|
59
|
+
#p [ :parse, :local, local, local.zone ]
|
52
60
|
|
53
61
|
secs =
|
54
62
|
if str_zone
|
@@ -56,19 +64,20 @@ module EtOrbi
|
|
56
64
|
else
|
57
65
|
zone.period_for_local(local).to_utc(local).to_f
|
58
66
|
end
|
67
|
+
#p [ :parse, :secs, secs ]
|
59
68
|
|
60
69
|
EoTime.new(secs, zone)
|
61
70
|
end
|
62
71
|
|
63
72
|
def make_time(*a)
|
64
73
|
|
65
|
-
#p a
|
74
|
+
#p [ :mt, a ]
|
66
75
|
zone = a.length > 1 ? get_tzone(a.last) : nil
|
67
76
|
a.pop if zone
|
68
77
|
#p [ :mt, zone ]
|
69
78
|
|
70
79
|
o = a.length > 1 ? a : a.first
|
71
|
-
#p o
|
80
|
+
#p [ :mt, :o, o ]
|
72
81
|
|
73
82
|
case o
|
74
83
|
when Time then make_from_time(o, zone)
|
@@ -87,11 +96,11 @@ module EtOrbi
|
|
87
96
|
z =
|
88
97
|
zone ||
|
89
98
|
get_tzone(t.zone) ||
|
90
|
-
(
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
99
|
+
get_local_tzone(t)
|
100
|
+
|
101
|
+
z ||= t.zone
|
102
|
+
# pass the abbreviation anyway,
|
103
|
+
# it will be used in resulting the error message
|
95
104
|
|
96
105
|
EoTime.new(t.to_f, z)
|
97
106
|
end
|
@@ -115,6 +124,7 @@ module EtOrbi
|
|
115
124
|
|
116
125
|
def make_from_string(s, zone)
|
117
126
|
|
127
|
+
#p [ :mfs, s, zone ]
|
118
128
|
parse(s, zone: zone)
|
119
129
|
end
|
120
130
|
|
@@ -160,6 +170,21 @@ module EtOrbi
|
|
160
170
|
end
|
161
171
|
end
|
162
172
|
|
173
|
+
def render_nozone_time(seconds)
|
174
|
+
|
175
|
+
t =
|
176
|
+
Time.utc(0) + seconds
|
177
|
+
ts =
|
178
|
+
t.strftime('%Y-%m-%d %H:%M:%S') +
|
179
|
+
".#{(seconds % 1).to_s.split('.').last}"
|
180
|
+
z =
|
181
|
+
EtOrbi.local_tzone ?
|
182
|
+
EtOrbi.local_tzone.period_for_local(t).abbreviation.to_s :
|
183
|
+
nil
|
184
|
+
|
185
|
+
"(secs:#{seconds},utc~:#{ts.inspect},ltz~:#{z.inspect})"
|
186
|
+
end
|
187
|
+
|
163
188
|
def platform_info
|
164
189
|
|
165
190
|
etos = Proc.new { |k, v| "#{k}:#{v.inspect}" }
|
@@ -173,19 +198,52 @@ module EtOrbi
|
|
173
198
|
'rp' => RUBY_PLATFORM,
|
174
199
|
'eov' => EtOrbi::VERSION,
|
175
200
|
'rorv' => (Rails::VERSION::STRING rescue nil),
|
176
|
-
'astz' => Time.
|
177
|
-
# Active Support Time.zone
|
201
|
+
'astz' => ([ Time.zone.class, Time.zone.tzinfo.name ] rescue nil),
|
178
202
|
}.collect(&etos).join(',') + ',' +
|
179
203
|
gather_tzs.collect(&etos).join(',') +
|
180
204
|
')'
|
181
205
|
end
|
182
206
|
|
183
207
|
alias make make_time
|
208
|
+
|
209
|
+
# For `make info`
|
210
|
+
#
|
211
|
+
def _make_info
|
212
|
+
|
213
|
+
puts render_nozone_time(Time.now.to_f)
|
214
|
+
puts platform_info
|
215
|
+
end
|
216
|
+
|
217
|
+
protected
|
218
|
+
|
219
|
+
def get_local_tzone(t)
|
220
|
+
|
221
|
+
# lt = local_tzone
|
222
|
+
# lp = lt.period_for_local(t)
|
223
|
+
# ab = lp.abbreviation.to_s
|
224
|
+
#
|
225
|
+
# return lt \
|
226
|
+
# if ab == t.zone
|
227
|
+
# return lt \
|
228
|
+
# if ab.match(/\A[-+]\d{2}(:?\d{2})?\z/) && lp.utc_offset == t.utc_offset
|
229
|
+
#
|
230
|
+
# nil
|
231
|
+
|
232
|
+
l = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec, t.usec)
|
233
|
+
|
234
|
+
t.zone == l.zone ? local_tzone : nil
|
235
|
+
end
|
184
236
|
end
|
185
237
|
|
238
|
+
# Our EoTime class (which quacks like a ::Time).
|
239
|
+
#
|
240
|
+
# An EoTime instance should respond to most of the methods ::Time instances
|
241
|
+
# respond to. If a method is missing, feel free to open an issue to
|
242
|
+
# ask (politely) for it. If it makes sense, it'll get added, else
|
243
|
+
# a workaround will get suggested.
|
244
|
+
# The immediate workaround is to call #to_t on the EoTime instance to get
|
245
|
+
# equivalent ::Time instance in the local, current, timezone.
|
186
246
|
#
|
187
|
-
# our EoTime class (which quacks like a ::Time)
|
188
|
-
|
189
247
|
class EoTime
|
190
248
|
|
191
249
|
#
|
@@ -237,8 +295,8 @@ module EtOrbi
|
|
237
295
|
|
238
296
|
fail ArgumentError.new(
|
239
297
|
"cannot determine timezone from #{zone.inspect}" +
|
240
|
-
"\n#{render_nozone_time(s)}" +
|
241
|
-
"\n#{
|
298
|
+
"\n#{EtOrbi.render_nozone_time(s)}" +
|
299
|
+
"\n#{EtOrbi.platform_info.sub(',debian:', ",\ndebian:")}" +
|
242
300
|
"\nTry setting `ENV['TZ'] = 'Continent/City'` in your script " +
|
243
301
|
"(see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)" +
|
244
302
|
(defined?(TZInfo::Data) ? '' : "\nand adding gem 'tzinfo-data'")
|
@@ -259,22 +317,25 @@ module EtOrbi
|
|
259
317
|
@zone = self.class.get_tzone(zone || :current)
|
260
318
|
end
|
261
319
|
|
320
|
+
# Returns this ::EtOrbi::EoTime as a ::Time instance
|
321
|
+
# in the current UTC timezone.
|
322
|
+
#
|
262
323
|
def utc
|
263
324
|
|
264
325
|
Time.utc(1970, 1, 1) + @seconds
|
265
326
|
end
|
266
327
|
|
328
|
+
# Returns true if this ::EtOrbi::EoTime instance timezone is UTC.
|
329
|
+
# Returns false else.
|
330
|
+
#
|
267
331
|
def utc?
|
268
332
|
|
269
333
|
%w[ zulu utc gmt ].include?(@zone.canonical_identifier.downcase)
|
270
|
-
|
271
|
-
#t = Time.now
|
272
|
-
#@zone.period_for_local(t).utc_offset == 0 &&
|
273
|
-
#@zone.period_for_local(t + 183 * 24 * 3600).utc_offset == 0
|
274
334
|
end
|
275
335
|
|
276
336
|
alias getutc utc
|
277
337
|
alias getgm utc
|
338
|
+
alias to_utc_time utc
|
278
339
|
|
279
340
|
def to_f
|
280
341
|
|
@@ -293,15 +354,18 @@ module EtOrbi
|
|
293
354
|
to_time.strftime(format)
|
294
355
|
end
|
295
356
|
|
296
|
-
# Returns a
|
357
|
+
# Returns this ::EtOrbi::EoTime as a ::Time instance
|
358
|
+
# in the current timezone.
|
297
359
|
#
|
298
|
-
#
|
360
|
+
# Has a #to_t alias.
|
299
361
|
#
|
300
|
-
def
|
362
|
+
def to_local_time
|
301
363
|
|
302
|
-
|
364
|
+
Time.at(@seconds)
|
303
365
|
end
|
304
366
|
|
367
|
+
alias to_t to_local_time
|
368
|
+
|
305
369
|
def is_dst?
|
306
370
|
|
307
371
|
@zone.period_for_utc(utc).std_offset != 0
|
@@ -325,9 +389,6 @@ module EtOrbi
|
|
325
389
|
|
326
390
|
def utc_offset
|
327
391
|
|
328
|
-
#@zone.period_for_utc(utc).utc_offset
|
329
|
-
#@zone.period_for_utc(utc).utc_total_offset
|
330
|
-
#@zone.period_for_utc(utc).std_offset
|
331
392
|
@zone.period_for_utc(utc).utc_offset
|
332
393
|
end
|
333
394
|
|
@@ -340,9 +401,11 @@ module EtOrbi
|
|
340
401
|
|
341
402
|
def ==(o)
|
342
403
|
|
343
|
-
o.is_a?(EoTime) &&
|
404
|
+
o.is_a?(EoTime) &&
|
405
|
+
o.seconds == @seconds &&
|
406
|
+
(o.zone == @zone || o.zone.current_period == @zone.current_period)
|
344
407
|
end
|
345
|
-
#alias
|
408
|
+
#alias eql? == # FIXME see Object#== (ri)
|
346
409
|
|
347
410
|
def >(o); @seconds > _to_f(o); end
|
348
411
|
def >=(o); @seconds >= _to_f(o); end
|
@@ -436,6 +499,15 @@ module EtOrbi
|
|
436
499
|
|
437
500
|
protected
|
438
501
|
|
502
|
+
# Returns a Ruby Time instance.
|
503
|
+
#
|
504
|
+
# Warning: the timezone of that Time instance will be UTC.
|
505
|
+
#
|
506
|
+
def to_time
|
507
|
+
|
508
|
+
@time ||= begin; u = utc; @zone.period_for_utc(u).to_local(u); end
|
509
|
+
end
|
510
|
+
|
439
511
|
def count_weeks(dir)
|
440
512
|
|
441
513
|
c = 0
|
@@ -448,21 +520,6 @@ module EtOrbi
|
|
448
520
|
c
|
449
521
|
end
|
450
522
|
|
451
|
-
def render_nozone_time(seconds)
|
452
|
-
|
453
|
-
t =
|
454
|
-
Time.utc(0) + seconds
|
455
|
-
ts =
|
456
|
-
t.strftime('%Y-%m-%d %H:%M:%S') +
|
457
|
-
".#{(seconds % 1).to_s.split('.').last}"
|
458
|
-
z =
|
459
|
-
EtOrbi.local_tzone ?
|
460
|
-
EtOrbi.local_tzone.period_for_local(t).abbreviation.to_s :
|
461
|
-
nil
|
462
|
-
|
463
|
-
"(secs:#{seconds},utc~:#{ts.inspect},ltz~:#{z.inspect})"
|
464
|
-
end
|
465
|
-
|
466
523
|
def strfz(code)
|
467
524
|
|
468
525
|
return @zone.name if code == '%/Z'
|
@@ -549,15 +606,23 @@ module EtOrbi
|
|
549
606
|
tz = ::TZInfo::Timezone.get(etz) rescue nil
|
550
607
|
return tz if tz
|
551
608
|
|
552
|
-
|
553
|
-
|
609
|
+
if Time.respond_to?(:zone) && Time.zone.respond_to?(:tzinfo)
|
610
|
+
tz = Time.zone.tzinfo
|
611
|
+
return tz if tz
|
612
|
+
end
|
613
|
+
|
614
|
+
tz = ::TZInfo::Timezone.get(os_tz) rescue nil
|
554
615
|
return tz if tz
|
555
616
|
|
556
617
|
tzs = determine_local_tzones
|
557
|
-
|
558
618
|
(etz && tzs.find { |z| z.name == etz }) || tzs.first
|
559
619
|
end
|
560
620
|
|
621
|
+
def os_tz
|
622
|
+
|
623
|
+
debian_tz || centos_tz || osx_tz
|
624
|
+
end
|
625
|
+
|
561
626
|
#
|
562
627
|
# protected module methods
|
563
628
|
|
@@ -654,11 +719,6 @@ module EtOrbi
|
|
654
719
|
nil
|
655
720
|
rescue; nil; end
|
656
721
|
|
657
|
-
# def find_tz
|
658
|
-
#
|
659
|
-
# debian_tz || centos_tz || osx_tz
|
660
|
-
# end
|
661
|
-
|
662
722
|
def gather_tzs
|
663
723
|
|
664
724
|
{ :debian => debian_tz, :centos => centos_tz, :osx => osx_tz }
|
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.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.6.13
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: time with zones
|