et-orbi 1.2.1 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0e76c51b164aaa3749e6865594a141100e4e6e1e
4
- data.tar.gz: dbc982c799a79da7408ed7e7cb9ff9d9481ea91c
2
+ SHA256:
3
+ metadata.gz: 23ff138170f965f0a2dc35d38aaa08123ddfd97176d76f5e1b2136306eec812e
4
+ data.tar.gz: 193d8bca6b8cfb34f023aadb504e127fd3f187eb64c10f546327510c8f487e04
5
5
  SHA512:
6
- metadata.gz: b2780226defd2f1ad6aad04291e6dc77bcf9e56d60c75f2f68ea0471f931bf75f434cf44e52a17d5e41dff79947c571d7179cf70759d0429e3d6631f02f4d996
7
- data.tar.gz: 8cad684822abf9f08a3811867a5c0010e24d175527fa65c7f4f67e580fd540b5e798cf94131b95b9942ec239b00c1fccc470a5c8a0cadeacfd4dfa3c8f5299a0
6
+ metadata.gz: 9a5747b65189567c49a9dda0936bac7d947deaa8a5067ba4d311d1c80032722baae682acfc111488d8c6b3139fa41238dfec645279983449312c6f5aa8881eb9
7
+ data.tar.gz: 2173668af72a6c2aff4e992201d5c74ffe5f87023f6e52c4c42389c28bb8cab4a231c55142bbc9c12513173260c80bf3b372c0ccad555900f6a7efad01e35482
data/CHANGELOG.md CHANGED
@@ -2,6 +2,37 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## et-orbi 1.2.7 released 2022-03-09
6
+
7
+ - Fix the wday_in_month computation for floraison/fugit#67
8
+
9
+
10
+ ## et-orbi 1.2.6 released 2021-10-30
11
+
12
+ - Favour IANA timezone name in EtOrbi.make_time
13
+
14
+
15
+ ## et-orbi 1.2.5 released 2021-09-18
16
+
17
+ - Re-use the DateTime.parse result
18
+
19
+
20
+ ## et-orbi 1.2.4 released 2020-03-18
21
+
22
+ - Do not call Chronic (even if enabled) from make_from_array, gh-28
23
+ - Be modern, use strftime '%6N', join Ruby 2.x :-)
24
+
25
+
26
+ ## et-orbi 1.2.3 released 2020-03-06
27
+
28
+ - Introduce EtOrbi.chronic_enabled = false and EtOrbi.chronic_enabled?, gh-26
29
+
30
+
31
+ ## et-orbi 1.2.2 released 2019-08-19
32
+
33
+ - Let EoTime#== accept EoTime or ::Time instances, gh-20, gh-7
34
+
35
+
5
36
  ## et-orbi 1.2.1 released 2019-05-01
6
37
 
7
38
  - More US time zone corrections, Vais Salikhov, gh-19
data/CREDITS.md CHANGED
@@ -1,6 +1,12 @@
1
1
 
2
2
  # et-orbi credits
3
3
 
4
+ * phibid, for https://github.com/floraison/fugit/issues/67
5
+ * Peter Goldstein, https://github.com/petergoldstein GHA 3.3 j9.3, gh-32
6
+ * harsha-flipp (https://github.com/harsha-flipp) https://github.com/floraison/fugit/issues/63
7
+ * adank92 (https://github.com/adank92) https://github.com/ondrejbartas/sidekiq-cron/issues/276 gh-28
8
+ * Stan Hu (https://github.com/stanhu) Chronic toubles, gh-24, gh-26, etc
9
+ * d-m-u (https://github.com/d-m-u) EoTime#==(Time), gh-20, gh-7
4
10
  * Vais Salikhov (https://github.com/vais) missing US timezone aliases, gh-18 gh-19
5
11
  * Wenhui Wang https://github.com/w11th .parse vs Chronic+ActiveSupport, fugit 11
6
12
  * Marcel https://github.com/MTRNord "Mitteleuropaeische Sommerzeit", gh-15
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2017-2019, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2017-2022, John Mettraux, jmettraux+flor@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/Makefile CHANGED
@@ -31,7 +31,7 @@ build: gemspec_validate
31
31
  mv $(NAME)-$(VERSION).gem pkg/
32
32
 
33
33
  push: build
34
- gem push pkg/$(NAME)-$(VERSION).gem
34
+ gem push --otp "$(OTP)" pkg/$(NAME)-$(VERSION).gem
35
35
 
36
36
  spec:
37
37
  bundle exec rspec
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
 
2
2
  # et-orbi
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/floraison/et-orbi.svg)](http://travis-ci.org/floraison/et-orbi)
5
- [![Build status](https://ci.appveyor.com/api/projects/status/6tbo9lk9qdor8ipl?svg=true)](https://ci.appveyor.com/project/jmettraux/et-orbi)
4
+ [![tests](https://github.com/floraison/et-orbi/workflows/test/badge.svg)](https://github.com/floraison/et-orbi/actions)
6
5
  [![Gem Version](https://badge.fury.io/rb/et-orbi.svg)](http://badge.fury.io/rb/et-orbi)
7
6
  [![Join the chat at https://gitter.im/floraison/fugit](https://badges.gitter.im/floraison/fugit.svg)](https://gitter.im/floraison/fugit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
7
 
@@ -16,6 +15,8 @@ require 'et-orbi'
16
15
 
17
16
  EtOrbi.now
18
17
  # => #<EtOrbi::EoTime:0x007f94d94 ...>
18
+ EtOrbi.now('Asia/Singapore')
19
+ # => #<EtOrbi::EoTime:0x39c96e48 @time=nil, @zone=#<TZInfo::DataTimezone: Asia/Singapore>...>
19
20
  EtOrbi.parse('2017-12-13 13:00:00 America/Jamaica')
20
21
  # => #<EtOrbi::EoTime:0x007f94d90 @zone=#<TZInfo::DataTimezone: America/Jamaica>...>
21
22
  EtOrbi.make_time(Time.now)
@@ -37,7 +38,7 @@ EtOrbi.parse('1970-01-01 03:00:00 Europe/Moscow')
37
38
  ```
38
39
 
39
40
  More about `EtOrbi::EoTime` instances:
40
- ```
41
+ ```ruby
41
42
  eot = EtOrbi::EoTime.new(0, 'Europe/Moscow')
42
43
 
43
44
  eot.to_local_time.class # => Time
@@ -69,6 +70,52 @@ EtOrbi.platform_info
69
70
  # astz: ActiveSupport provided Time.zone
70
71
  ```
71
72
 
73
+ ### Chronic integration
74
+
75
+ By default, et-orbi relies on [Chronic](https://github.com/mojombo/chronic) to parse strings like "tomorrow" or "friday 1pm", if `Chronic` is present.
76
+
77
+ ```ruby
78
+ EtOrbi.parse('tomorrow')
79
+ # => #<EtOrbi::EoTime:0x007fbc6aa8a560
80
+ # @seconds=1575687600.0,
81
+ # @zone=#<TZInfo::TimezoneProxy: Asia/Tokyo>,
82
+ # @time=nil>
83
+ EtOrbi.parse('tomorrow').to_s
84
+ # => "2019-12-07 12:00:00 +0900"
85
+ ```
86
+
87
+ This is a poor design choice I replicated from [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
88
+
89
+ Of course this leads to [issues](https://gitlab.com/gitlab-org/gitlab/issues/37014).
90
+
91
+ It's probably better to have Chronic do its work outside of et-orbi, like in:
92
+ ```ruby
93
+ EtOrbi.parse(Chronic.parse('tomorrow').to_s).to_s
94
+ # => "2019-12-07 12:00:00 +0900"
95
+ ```
96
+
97
+ If one has Chronic present in their project but doesn't want it to interfere with et-orbi, it can be disabled at `parse` call:
98
+ ```ruby
99
+ EtOrbi.parse('tomorrow')
100
+ # => #<EtOrbi::EoTime:0x007ffb5b2a2390
101
+ # @seconds=1575687600.0,
102
+ # @zone=#<TZInfo::TimezoneProxy: Asia/Tokyo>,
103
+ # @time=nil>
104
+ EtOrbi.parse('tomorrow', enable_chronic: false)
105
+ # ArgumentError: No time information in "tomorrow"
106
+ # from /home/jmettraux/w/et-orbi/lib/et-orbi/make.rb:31:in `rescue in parse'
107
+ ```
108
+ or at the et-orbi level:
109
+ ```ruby
110
+ irb(main):007:0> EtOrbi.chronic_enabled = false
111
+ # => false
112
+ irb(main):008:0> EtOrbi.chronic_enabled?
113
+ # => false
114
+ EtOrbi.parse('tomorrow')
115
+ # ArgumentError: No time information in "tomorrow"
116
+ # from /home/jmettraux/w/et-orbi/lib/et-orbi/make.rb:31:in `rescue in parse'
117
+ ```
118
+
72
119
  ### Rails?
73
120
 
74
121
  If Rails is present, `Time.zone` is provided and EtOrbi will use it, unless `ENV['TZ']` is set to a valid timezone name. Setting `ENV['TZ']` to nil can give back precedence to `Time.zone`.
data/et-orbi.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = [ 'John Mettraux' ]
12
12
  s.email = [ 'jmettraux+flor@gmail.com' ]
13
- s.homepage = 'http://github.com/floraison/et-orbi'
13
+ s.homepage = 'https://github.com/floraison/et-orbi'
14
14
  s.license = 'MIT'
15
15
  s.summary = 'time with zones'
16
16
 
data/lib/et-orbi/make.rb CHANGED
@@ -1,6 +1,15 @@
1
1
 
2
2
  module EtOrbi
3
3
 
4
+ @chronic_enabled = true
5
+ #
6
+ def self.chronic_enabled?
7
+ @chronic_enabled
8
+ end
9
+ def self.chronic_enabled=(b)
10
+ @chronic_enabled = b
11
+ end
12
+
4
13
  class << self
5
14
 
6
15
  def now(zone=nil)
@@ -12,28 +21,29 @@ module EtOrbi
12
21
 
13
22
  str, str_zone = extract_zone(str)
14
23
 
15
- if defined?(::Chronic) && t = ::Chronic.parse(str, opts)
16
-
24
+ if t = chronic_parse(str, opts)
17
25
  str = [ t.strftime('%F %T'), str_zone ].compact.join(' ')
18
26
  end
19
27
 
20
- begin
21
- DateTime.parse(str)
22
- rescue
23
- fail ArgumentError, "No time information in #{str.inspect}"
24
- end
25
- #end if RUBY_VERSION < '1.9.0'
26
- #end if RUBY_VERSION < '2.0.0'
27
- #
28
- # is necessary since Time.parse('xxx') in Ruby < 1.9 yields `now`
28
+ dt =
29
+ begin
30
+ DateTime.parse(str)
31
+ rescue
32
+ fail ArgumentError, "No time information in #{str.inspect}"
33
+ end
34
+ #end if RUBY_VERSION < '1.9.0'
35
+ #end if RUBY_VERSION < '2.0.0'
36
+ #
37
+ # is necessary since Time.parse('xxx') in Ruby < 1.9 yields `now`
29
38
 
30
39
  zone =
31
40
  opts[:zone] ||
32
41
  get_tzone(str_zone) ||
33
42
  determine_local_tzone
34
43
 
35
- local = Time.parse(str)
36
- secs = zone.local_to_utc(local).to_f
44
+ #local = Time.parse(str)
45
+ #secs = zone.local_to_utc(local).to_f
46
+ secs = zone.local_to_utc(dt).to_time.to_f
37
47
 
38
48
  EoTime.new(secs, zone)
39
49
  end
@@ -60,13 +70,24 @@ module EtOrbi
60
70
 
61
71
  protected
62
72
 
73
+ def chronic_parse(str, opts)
74
+
75
+ return false unless defined?(::Chronic)
76
+ return false unless opts.fetch(:enable_chronic) { self.chronic_enabled? }
77
+
78
+ os = opts
79
+ .select { |k, _| Chronic::Parser::DEFAULT_OPTIONS.keys.include?(k) }
80
+
81
+ ::Chronic.parse(str, os)
82
+ end
83
+
63
84
  def make_from_time(t, zone)
64
85
 
65
86
  z =
66
87
  zone ||
67
88
  get_as_tzone(t) ||
68
- get_tzone(t.zone) ||
69
- get_local_tzone(t)
89
+ get_local_tzone(t) ||
90
+ get_tzone(t.zone)
70
91
 
71
92
  z ||= t.zone
72
93
  # pass the abbreviation anyway,
@@ -86,10 +107,9 @@ module EtOrbi
86
107
 
87
108
  def make_from_array(a, zone)
88
109
 
89
- t = Time.utc(*a)
90
- s = t.strftime("%Y-%m-%d %H:%M:%S.#{'%06d' % t.usec}")
91
-
92
- make_from_string(s, zone)
110
+ parse(
111
+ Time.utc(*a).strftime('%Y-%m-%d %H:%M:%S.%6N'), # not a Chronic string
112
+ zone: zone, enable_chronic: false)
93
113
  end
94
114
 
95
115
  def make_from_string(s, zone)
data/lib/et-orbi/time.rb CHANGED
@@ -205,11 +205,24 @@ module EtOrbi
205
205
 
206
206
  def ==(o)
207
207
 
208
- o.is_a?(EoTime) &&
209
- o.seconds == @seconds &&
210
- (o.zone == @zone || o.zone.current_period == @zone.current_period)
208
+ if o.is_a?(EoTime)
209
+ o.seconds == @seconds &&
210
+ (o.zone == @zone || o.zone.current_period == @zone.current_period)
211
+ elsif o.is_a?(::Time)
212
+ (to_f * 1000).to_i == (o.to_f * 1000).to_i
213
+ else
214
+ false
215
+ end
211
216
  end
212
- #alias eql? == # FIXME see Object#== (ri)
217
+
218
+ # Nota Bene:
219
+ #
220
+ # Unlike ==, the equal? method should never be overridden by subclasses
221
+ # as it is used to determine object identity (that is, a.equal?(b) if and
222
+ # only if a is the same object as b)
223
+ #
224
+ # The eql? method returns true if obj and other refer to the same hash key.
225
+ # This is used by Hash to test members for equality.
213
226
 
214
227
  def >(o); @seconds > _to_f(o); end
215
228
  def >=(o); @seconds >= _to_f(o); end
@@ -283,7 +296,7 @@ module EtOrbi
283
296
 
284
297
  def to_time_s
285
298
 
286
- strftime("%H:%M:%S.#{'%06d' % usec}")
299
+ strftime('%H:%M:%S.%6N')
287
300
  end
288
301
 
289
302
  def inc(t, dir=1)
@@ -313,7 +326,8 @@ module EtOrbi
313
326
 
314
327
  def wday_in_month
315
328
 
316
- [ count_weeks(-1), - count_weeks(1) ]
329
+ [ count_weeks(EtOrbi.make_time(strftime('%F 12:00:00 %/Z')), -1),
330
+ - count_weeks(EtOrbi.make_time(strftime('%F 12:00:00 %/Z')) , 1) ]
317
331
  end
318
332
 
319
333
  def rweek
@@ -372,10 +386,11 @@ module EtOrbi
372
386
  @time ||= @zone.utc_to_local(utc)
373
387
  end
374
388
 
375
- def count_weeks(dir)
389
+ def count_weeks(start, dir)
376
390
 
377
391
  c = 0
378
- t = self
392
+ t = start
393
+
379
394
  until t.month != self.month
380
395
  c += 1
381
396
  t += dir * (7 * 24 * 3600)
@@ -414,7 +429,7 @@ module EtOrbi
414
429
 
415
430
  fail ArgumentError(
416
431
  "Comparison of EoTime with #{o.inspect} failed"
417
- ) unless o.is_a?(EoTime) || o.is_a?(Time)
432
+ ) unless o.respond_to?(:to_f)
418
433
 
419
434
  o.to_f
420
435
  end
data/lib/et-orbi/zones.rb CHANGED
@@ -13,7 +13,7 @@ module EtOrbi
13
13
  (?![-+])
14
14
  |Z
15
15
  )
16
- }x
16
+ }x.freeze
17
17
 
18
18
  # https://en.wikipedia.org/wiki/ISO_8601
19
19
  # Postel's law applies
data/lib/et-orbi.rb CHANGED
@@ -13,6 +13,6 @@ require 'et-orbi/zone'
13
13
 
14
14
  module EtOrbi
15
15
 
16
- VERSION = '1.2.1'
16
+ VERSION = '1.2.7'
17
17
  end
18
18
 
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.2.1
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-30 00:00:00.000000000 Z
11
+ date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo
@@ -73,15 +73,15 @@ files:
73
73
  - lib/et-orbi/zones.rb
74
74
  - lib/et_orbi.rb
75
75
  - lib/etorbi.rb
76
- homepage: http://github.com/floraison/et-orbi
76
+ homepage: https://github.com/floraison/et-orbi
77
77
  licenses:
78
78
  - MIT
79
79
  metadata:
80
- changelog_uri: http://github.com/floraison/et-orbi/blob/master/CHANGELOG.md
81
- documentation_uri: http://github.com/floraison/et-orbi
82
- bug_tracker_uri: http://github.com/floraison/et-orbi/issues
83
- homepage_uri: http://github.com/floraison/et-orbi
84
- source_code_uri: http://github.com/floraison/et-orbi
80
+ changelog_uri: https://github.com/floraison/et-orbi/blob/master/CHANGELOG.md
81
+ documentation_uri: https://github.com/floraison/et-orbi
82
+ bug_tracker_uri: https://github.com/floraison/et-orbi/issues
83
+ homepage_uri: https://github.com/floraison/et-orbi
84
+ source_code_uri: https://github.com/floraison/et-orbi
85
85
  post_install_message:
86
86
  rdoc_options: []
87
87
  require_paths:
@@ -97,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.6.14.1
100
+ rubygems_version: 3.1.2
102
101
  signing_key:
103
102
  specification_version: 4
104
103
  summary: time with zones