et-orbi 1.3.0 → 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: 2bff6c08f6ece712b2058c0e91120b4bc4fff8925a377fdd8079ec4bbe151a44
4
- data.tar.gz: 01ff0b2c74e2a62bb7b895fc83a2a993b2a5a2e1e6088fc4301848076b83a2f0
3
+ metadata.gz: 1fc097e4fc84ec60bd0c5576e2d20e44c8e1f93a25ca54d18705c8a15ac46d15
4
+ data.tar.gz: aaf8974a36588b4a339f97fb4ab18ac124d86d189874bb951489788000e4a66e
5
5
  SHA512:
6
- metadata.gz: 1d6da83141821bb9f8afe331b8a24caeb88ef8723ea1b34e8c3ce34c8028e0f50a6b254e16fb4501d1cee092cec716e82cac970d1fdef130206fbcc38004d2a5
7
- data.tar.gz: aa234212a99fb2c4991ee1cf081a34247f73bd01170d4cd3db2769c6c5d1d003543db0d08a887e4c544310e0da01f593d77d86f71c5b73e59cf029c5210fc075
6
+ metadata.gz: 7bbe86df96ee13a4884f680629d80b3965721d5f78aac42a712aadb18fa7c89160be8679aa3bcc74405cab8bf964e68b67d94efd2a87baf75cdfbe604e4c52c5
7
+ data.tar.gz: ba98fd3c1557f4a6c5aa741763c03d82ccf2e0254d751616939406b033392d0b7d34551ed54388e03bcd10df5273203345d75090ee98289c8e3c9c318a1a9490
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
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
+
5
11
  ## et-orbi 1.3.0 released 2025-08-08
6
12
 
7
13
  - Use probatio for testing
data/CREDITS.md CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  # et-orbi credits
3
3
 
4
+ * Hugh Kelsey https://github.com/hughkelsey fugit gh-94 rweek/rday rework
4
5
  * Keenan Brock https://github.com/kbrock version parsing and ostruct dep
5
6
  * Benjami Darcet https://github.com/bdarcet https://github.com/floraison/fugit/issues/67 gh-38
6
7
  * https://github.com/franckduche https://github.com/floraison/fugit/issues/67 gh-38
data/README.md CHANGED
@@ -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.
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)
@@ -358,30 +357,27 @@ module EtOrbi
358
357
  - count_weeks(EtOrbi.make_time(strftime('%F 12:00:00 %/Z')) , 1) ]
359
358
  end
360
359
 
361
- # "reference week", used in fugit for cron modulo notation
360
+ # "reference day", used in fugit for cron modulo notation
362
361
  #
363
- def rweek
362
+ def rday
364
363
 
365
- @rweek ||=
366
- begin
367
- ref = EtOrbi.make_time('2019-01-01 12:00:00', @zone)
368
- noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)
369
- ((noon - ref) / WEEK_S).floor + 1
370
- end
364
+ @rday ||= (
365
+ (EtOrbi.make_time(strftime('%F 12:00:00'), @zone) - rref) / DAY_S
366
+ ).floor
371
367
  end
372
368
 
373
369
  # "reference week", used in fugit for cron modulo notation
374
370
  #
375
- def rday
371
+ def rweek
376
372
 
377
- @rday ||=
378
- begin
379
- ref = EtOrbi.make_time('2019-01-01 12:00:00', @zone)
380
- noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)
381
- ((noon - ref) / DAY_S).floor + 1
382
- end
373
+ rday / 7
383
374
  end
384
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
+
385
381
  def reach(points)
386
382
 
387
383
  t = EoTime.new(self.to_f, @zone)
@@ -478,6 +474,40 @@ module EtOrbi
478
474
 
479
475
  o.to_f
480
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
481
511
  end
482
512
  end
483
513
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module EtOrbi
3
3
 
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
6
6
 
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.3.0
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: 2025-08-08 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