et-orbi 1.2.11 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7f008f08099e4efe55b1cdeef327f9dd043703196609615e52ec20499db141e
4
- data.tar.gz: d7d636ce1eaf898dbf76b8d8c94ea3aeaab02a462e9e646ead51502f975dcb93
3
+ metadata.gz: 1fc097e4fc84ec60bd0c5576e2d20e44c8e1f93a25ca54d18705c8a15ac46d15
4
+ data.tar.gz: aaf8974a36588b4a339f97fb4ab18ac124d86d189874bb951489788000e4a66e
5
5
  SHA512:
6
- metadata.gz: c3fbfbef817e8c176a66d38edac9924e8f557fbb12bceddc42249bdd773f74b1fa3792f6a3c7cfff1f3ecd1bf13ff293de7baa0f84da3418cd171574d8984c40
7
- data.tar.gz: 2c3176e291230ad074b11d475a823cfa6cbce12cd55295337fcf1c36a9bdf7b35453801d3d940bd72308420594afae61a31a96ff4282fc0e9cc966c02d3ddfaf
6
+ metadata.gz: 7bbe86df96ee13a4884f680629d80b3965721d5f78aac42a712aadb18fa7c89160be8679aa3bcc74405cab8bf964e68b67d94efd2a87baf75cdfbe604e4c52c5
7
+ data.tar.gz: ba98fd3c1557f4a6c5aa741763c03d82ccf2e0254d751616939406b033392d0b7d34551ed54388e03bcd10df5273203345d75090ee98289c8e3c9c318a1a9490
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## et-orbi 1.4.0 released 2025-09-28
6
+
7
+ - Rework EoTime #rweek and #rday
8
+ - Introduce EtOrbi.rweek_ref= (:sunday, :monday, :iso, :us, ...)
9
+
10
+
11
+ ## et-orbi 1.3.0 released 2025-08-08
12
+
13
+ - Use probatio for testing
14
+ - Drop unnecessary touch in EoTime#inc
15
+ - Let EtOrbi #+ and #- accept instances with #to_i or #to_f (not strs), gh-40
16
+ - Introduce EtOrbi.zone_abbreviation(zone_name, time)
17
+
18
+
5
19
  ## et-orbi 1.2.11 released 2024-03-23
6
20
 
7
21
  - Cache @rweek and @rday, not @ref, gh-38
data/CREDITS.md CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  # et-orbi credits
3
3
 
4
+ * Hugh Kelsey https://github.com/hughkelsey fugit gh-94 rweek/rday rework
5
+ * Keenan Brock https://github.com/kbrock version parsing and ostruct dep
4
6
  * Benjami Darcet https://github.com/bdarcet https://github.com/floraison/fugit/issues/67 gh-38
5
7
  * https://github.com/franckduche https://github.com/floraison/fugit/issues/67 gh-38
6
8
  * Igor Viktor https://github.com/gogainda gh-34
@@ -8,7 +10,7 @@
8
10
  * Peter Goldstein, https://github.com/petergoldstein GHA 3.3 j9.3, gh-32
9
11
  * harsha-flipp https://github.com/harsha-flipp https://github.com/floraison/fugit/issues/63
10
12
  * adank92 https://github.com/adank92 https://github.com/ondrejbartas/sidekiq-cron/issues/276 gh-28
11
- * Stan Hu https://github.com/stanhu Chronic toubles, gh-24, gh-26, etc
13
+ * Stan Hu https://github.com/stanhu Chronic troubles, gh-24, gh-26, etc
12
14
  * d-m-u https://github.com/d-m-u EoTime#==(Time), gh-20, gh-7
13
15
  * Vais Salikhov (https://github.com/vais) missing US timezone aliases, gh-18 gh-19
14
16
  * Wenhui Wang https://github.com/w11th .parse vs Chronic+ActiveSupport, fugit 11
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2017-2024, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2017-2025, 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
@@ -33,9 +33,9 @@ build: gemspec_validate
33
33
  push: build
34
34
  gem push --otp "$(OTP)" pkg/$(NAME)-$(VERSION).gem
35
35
 
36
- spec:
37
- bundle exec rspec
38
- test: spec
36
+ test:
37
+ bundle exec proba
38
+ spec: test
39
39
 
40
40
 
41
41
  ## specific to project ##
@@ -48,5 +48,5 @@ info:
48
48
 
49
49
  ## done ##
50
50
 
51
- .PHONY: count_lines scan gemspec_validate name cw build push spec info
51
+ .PHONY: count_lines scan gemspec_validate name cw build push test info
52
52
 
data/README.md CHANGED
@@ -43,7 +43,7 @@ eot = EtOrbi::EoTime.new(0, 'Europe/Moscow')
43
43
  eot.to_local_time.class # => Time
44
44
  eot.to_local_time.to_s # => "1970-01-01 09:00:00 +0900" (at least on my system)
45
45
 
46
- # For the rest, EtOrbi::EoTime mimicks ::Time
46
+ # For the rest, EtOrbi::EoTime mimics ::Time
47
47
  ```
48
48
 
49
49
  Helper methods:
@@ -69,6 +69,77 @@ EtOrbi.platform_info
69
69
  # astz: ActiveSupport provided Time.zone
70
70
  ```
71
71
 
72
+
73
+ ### #rweek and #rday (clarification et-orbi 1.4.0)
74
+
75
+ `EoTime#rweek` and `#rday` are mostly used in [fugit](https://github.com/floraison/fugit) for its [modulo extension](https://github.com/floraison/fugit?tab=readme-ov-file#the-modulo-extension).
76
+
77
+ By default (since et-orbi 1.4.0), the "reference week" for et-orbi
78
+ starts on Monday 2018-12-31, its `#rweek` 0 and `#rday` 0
79
+
80
+ ```ruby
81
+ class EtOrbi::EoTime;
82
+ def rr; [ strftime('%A'), rweek, rday ]; end
83
+ end
84
+
85
+ EtOrbi.rweek_ref # => '2018-12-31'
86
+
87
+ # rw rd
88
+ EtOrbi.parse('2018-12-29').rr # => [ "Saturday", -1, -2 ]
89
+ EtOrbi.parse('2018-12-30').rr # => [ "Sunday", -1, -1 ]
90
+ EtOrbi.parse('2018-12-31').rr # => [ "Monday", 0, 0 ]
91
+ ```
92
+
93
+ Users living in the US, in Canada, or in the Philippines where the week start on Sunday can tune their et-orbi:
94
+ ```ruby
95
+ class EtOrbi::EoTime;
96
+ def rr; [ strftime('%A'), rweek, rday ]; end
97
+ end
98
+
99
+ EtOrbi.rweek_ref = :sunday
100
+ EtOrbi.rweek_ref # => '2018-12-30'
101
+
102
+ # rw rd
103
+ EtOrbi.parse('2018-12-29').rr # => [ "Saturday", -1, -1 ]
104
+ EtOrbi.parse('2018-12-30').rr # => [ "Sunday", 0, 0 ]
105
+ EtOrbi.parse('2018-12-31').rr # => [ "Monday", 0, 1 ]
106
+ ```
107
+
108
+ You can set the `rweek_ref` to `:sunday`, `:saturday`, `:monday`, or `:iso`, `:us`, or `:default`.
109
+
110
+ `:sunday` and `:us` are equivalent. `:monday`, `:iso`, and `:default` are equivalent.
111
+
112
+ If you feel like it, you can choose your own reference:
113
+
114
+ ```ruby
115
+ class EtOrbi::EoTime;
116
+ def rr; [ strftime('%A'), rweek, rday ]; end
117
+ end
118
+
119
+ EtOrbi.rweek_ref = '2025-09-28'
120
+
121
+ # rw rd
122
+ EtOrbi.parse('2018-12-29').rr # => [ "Saturday", -353, -2465 ]
123
+ EtOrbi.parse('2018-12-30').rr # => [ "Sunday", -352, -2464 ]
124
+ EtOrbi.parse('2018-12-31').rr # => [ "Monday", -352, -2463 ]
125
+ ```
126
+
127
+ Before et-orbi 1.4.0, the computation was a bit different, yielding:
128
+ ```ruby
129
+ class EtOrbi::EoTime;
130
+ def rr; [ strftime('%A'), rweek, rday ]; end
131
+ end
132
+
133
+ # rw rd
134
+ EtOrbi.parse('2018-12-29').rr # => [ "Saturday", 0, -2 ]
135
+ EtOrbi.parse('2018-12-30').rr # => [ "Sunday", 0, -1 ]
136
+ EtOrbi.parse('2018-12-31').rr # => [ "Monday", 0, 0 ]
137
+ EtOrbi.parse('2019-01-01').rr # => [ "Tuesday", 1, 1 ]
138
+ ```
139
+
140
+ This change was motivated by [fugit gh-114](https://github.com/floraison/fugit/issues/114).
141
+
142
+
72
143
  ### Chronic integration
73
144
 
74
145
  By default, et-orbi relies on [Chronic](https://github.com/mojombo/chronic) to parse strings like "tomorrow" or "friday 1pm", if `Chronic` is present.
@@ -115,6 +186,14 @@ EtOrbi.parse('tomorrow')
115
186
  # from /home/jmettraux/w/et-orbi/lib/et-orbi/make.rb:31:in `rescue in parse'
116
187
  ```
117
188
 
189
+ ### Testing
190
+
191
+ To run tests, use `proba`:
192
+
193
+ ```
194
+ bundle exec proba
195
+ ```
196
+
118
197
  ### Rails?
119
198
 
120
199
  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
@@ -1,12 +1,11 @@
1
1
 
2
- Gem::Specification.new do |s|
2
+ require File.expand_path('../lib/et-orbi/version.rb', __FILE__)
3
3
 
4
- s.name = 'et-orbi'
5
4
 
6
- s.version = File.read(
7
- File.expand_path('../lib/et-orbi.rb', __FILE__)
8
- ).match(/ VERSION *= *['"]([^'"]+)/)[1]
5
+ Gem::Specification.new do |s|
9
6
 
7
+ s.name = 'et-orbi'
8
+ s.version = EtOrbi::VERSION
10
9
  s.platform = Gem::Platform::RUBY
11
10
  s.authors = [ 'John Mettraux' ]
12
11
  s.email = [ 'jmettraux+flor@gmail.com' ]
@@ -26,6 +25,7 @@ Time zones for fugit and rufus-scheduler. Urbi et Orbi.
26
25
  'homepage_uri' => s.homepage,
27
26
  'source_code_uri' => s.homepage,
28
27
  #'wiki_uri' => s.homepage + '/wiki',
28
+ 'rubygems_mfa_required' => 'true',
29
29
  }
30
30
 
31
31
  #s.files = `git ls-files`.split("\n")
@@ -48,8 +48,11 @@ Time zones for fugit and rufus-scheduler. Urbi et Orbi.
48
48
 
49
49
  #s.add_runtime_dependency 'raabro', '>= 1.1.3'
50
50
 
51
- s.add_development_dependency 'rspec', '~> 3.8'
51
+ #s.add_development_dependency 'rspec', '~> 3.8'
52
+ s.add_development_dependency 'ostruct'
53
+ s.add_development_dependency 'probatio', '~> 1.3'
52
54
  s.add_development_dependency 'chronic', '~> 0.10'
55
+ #s.add_development_dependency 'activesupport', '~> 8.0'
53
56
 
54
57
  s.require_path = 'lib'
55
58
  end
data/lib/et-orbi/info.rb CHANGED
@@ -17,6 +17,7 @@ module EtOrbi
17
17
  'win' => Gem.win_platform?,
18
18
  'rorv' => (Rails::VERSION::STRING rescue nil),
19
19
  'astz' => ([ Time.zone.class, Time.zone.tzinfo.name ] rescue nil),
20
+ 'chronic' => (Chronic::VERSION rescue nil),
20
21
  'eov' => EtOrbi::VERSION,
21
22
  'eotnz' => '???',
22
23
  'eotnfz' => '???',
data/lib/et-orbi/time.rb CHANGED
@@ -91,13 +91,12 @@ module EtOrbi
91
91
  touch
92
92
  end
93
93
 
94
- # Nullify the "caches" used by #to_time, #rweek, and others
94
+ # Nullify the "caches" used by #to_time, #rday, and others
95
95
  #
96
96
  def touch
97
97
 
98
98
  @time = nil
99
99
  @rday = nil
100
- @rweek = nil
101
100
  end
102
101
 
103
102
  def seconds=(f)
@@ -316,24 +315,32 @@ module EtOrbi
316
315
 
317
316
  def inc(t, dir=1)
318
317
 
319
- r =
320
- case t
321
- when Numeric
322
- nt = self.dup
323
- nt.seconds += dir * t.to_f
324
- nt
325
- when ::Time, ::EtOrbi::EoTime
326
- fail ArgumentError.new(
327
- "Cannot add #{t.class} to EoTime") if dir > 0
328
- @seconds + dir * t.to_f
318
+ case t
319
+ when ::Time, ::EtOrbi::EoTime
320
+
321
+ fail(
322
+ ArgumentError.new("Cannot add #{t.class} to EoTime instance")
323
+ ) if dir > 0
324
+
325
+ @seconds + dir * t.to_f
326
+
327
+ when String
328
+
329
+ false
330
+
331
+ else
332
+
333
+ if t.respond_to?(:to_f)
334
+ nt = self.dup; nt.seconds += dir * t.to_f; nt
335
+ elsif t.respond_to?(:to_i)
336
+ nt = self.dup; nt.seconds += dir * t.to_i; nt
329
337
  else
330
- fail ArgumentError.new(
331
- "Cannot call add or subtract #{t.class} to EoTime instance")
338
+ false
332
339
  end
333
340
 
334
- touch
335
-
336
- r
341
+ end || fail(
342
+ ArgumentError.new(
343
+ "Cannot call add or subtract #{t.class} on EoTime instance"))
337
344
  end
338
345
 
339
346
  def localtime(zone=nil)
@@ -350,30 +357,27 @@ module EtOrbi
350
357
  - count_weeks(EtOrbi.make_time(strftime('%F 12:00:00 %/Z')) , 1) ]
351
358
  end
352
359
 
353
- # "reference week", used in fugit for cron modulo notation
360
+ # "reference day", used in fugit for cron modulo notation
354
361
  #
355
- def rweek
362
+ def rday
356
363
 
357
- @rweek ||=
358
- begin
359
- ref = EtOrbi.make_time('2019-01-01 12:00:00', @zone)
360
- noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)
361
- ((noon - ref) / WEEK_S).floor + 1
362
- end
364
+ @rday ||= (
365
+ (EtOrbi.make_time(strftime('%F 12:00:00'), @zone) - rref) / DAY_S
366
+ ).floor
363
367
  end
364
368
 
365
369
  # "reference week", used in fugit for cron modulo notation
366
370
  #
367
- def rday
371
+ def rweek
368
372
 
369
- @rday ||=
370
- begin
371
- ref = EtOrbi.make_time('2019-01-01 12:00:00', @zone)
372
- noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)
373
- ((noon - ref) / DAY_S).floor + 1
374
- end
373
+ rday / 7
375
374
  end
376
375
 
376
+ # A debug method, seen in its first iteration in
377
+ # https://github.com/floraison/et-orbi?tab=readme-ov-file#rweek-and-rday-clarification-et-orbi-140
378
+ #
379
+ def rr; [ strftime('%F %a'), rweek, rday ]; end
380
+
377
381
  def reach(points)
378
382
 
379
383
  t = EoTime.new(self.to_f, @zone)
@@ -470,6 +474,40 @@ module EtOrbi
470
474
 
471
475
  o.to_f
472
476
  end
477
+
478
+ # Gives back the Eotime instance pointing to the reference day
479
+ # used to compute #rweek and #rday
480
+ #
481
+ def rref
482
+
483
+ EtOrbi.make_time("#{::EtOrbi.rweek_ref} 12:00:00", @zone)
484
+ end
485
+ end
486
+ end
487
+
488
+ module EtOrbi
489
+
490
+ #RWEEK_REF_DEFAULT = '2019-01-01'.freeze
491
+ RWEEK_REF_DEFAULT = '2018-12-31'.freeze # monday / ISO 8601
492
+
493
+ class << self
494
+
495
+ def rweek_ref=(x)
496
+
497
+ @rweek_ref =
498
+ case x
499
+ when /^[21]\d{3}-(1[012]|0?\d)-(3[01]|[21]\d|0?\d)$/ then x
500
+ when :saturday then '2019-01-05'
501
+ when :sunday, :us then '2018-12-30'
502
+ when :monday, :default, :iso then RWEEK_REF_DEFAULT
503
+ else fail(ArgumentError.new("not a valid rweek_ref #{x.inspect}"))
504
+ end
505
+ end
506
+
507
+ def rweek_ref
508
+
509
+ @rweek_ref || RWEEK_REF_DEFAULT
510
+ end
473
511
  end
474
512
  end
475
513
 
@@ -0,0 +1,6 @@
1
+
2
+ module EtOrbi
3
+
4
+ VERSION = '1.4.0'
5
+ end
6
+
data/lib/et-orbi/zones.rb CHANGED
@@ -77,7 +77,7 @@ module EtOrbi
77
77
  tz = (etz && tzs.find { |z| z.name == etz }) || tzs.first
78
78
  return tz if tz
79
79
 
80
- # then, fall back to GMT offest :-(
80
+ # then, fall back to GMT offset :-(
81
81
 
82
82
  n = Time.now
83
83
 
@@ -161,6 +161,18 @@ module EtOrbi
161
161
  end
162
162
  end
163
163
 
164
+ def zone_abbreviation(zone_name, time)
165
+
166
+ tz = ::TZInfo::Timezone.get(zone_name)
167
+
168
+ ts = tz.period_for_local(time, true) rescue -1
169
+ tw = tz.period_for_local(time, false) rescue -2
170
+
171
+ return ts.abbreviation.to_s if ts == tw
172
+
173
+ tz.period_for_local(time + 2 * 3600).abbreviation.to_s
174
+ end
175
+
164
176
  def tweak_zone_name(name)
165
177
 
166
178
  return name unless (name.match(/./) rescue nil)
data/lib/et-orbi.rb CHANGED
@@ -4,15 +4,10 @@ require 'time'
4
4
 
5
5
  require 'tzinfo'
6
6
 
7
+ require 'et-orbi/version'
7
8
  require 'et-orbi/info'
8
9
  require 'et-orbi/make'
9
10
  require 'et-orbi/time'
10
11
  require 'et-orbi/zones'
11
12
  require 'et-orbi/zone'
12
13
 
13
-
14
- module EtOrbi
15
-
16
- VERSION = '1.2.11'
17
- end
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.11
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-23 00:00:00.000000000 Z
11
+ date: 2025-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo
@@ -25,19 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: ostruct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: probatio
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '3.8'
47
+ version: '1.3'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '3.8'
54
+ version: '1.3'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: chronic
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -69,6 +83,7 @@ files:
69
83
  - lib/et-orbi/info.rb
70
84
  - lib/et-orbi/make.rb
71
85
  - lib/et-orbi/time.rb
86
+ - lib/et-orbi/version.rb
72
87
  - lib/et-orbi/zone.rb
73
88
  - lib/et-orbi/zones.rb
74
89
  - lib/et_orbi.rb
@@ -82,6 +97,7 @@ metadata:
82
97
  bug_tracker_uri: https://github.com/floraison/et-orbi/issues
83
98
  homepage_uri: https://github.com/floraison/et-orbi
84
99
  source_code_uri: https://github.com/floraison/et-orbi
100
+ rubygems_mfa_required: 'true'
85
101
  post_install_message:
86
102
  rdoc_options: []
87
103
  require_paths:
@@ -97,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
113
  - !ruby/object:Gem::Version
98
114
  version: '0'
99
115
  requirements: []
100
- rubygems_version: 3.4.10
116
+ rubygems_version: 3.4.19
101
117
  signing_key:
102
118
  specification_version: 4
103
119
  summary: time with zones