philiprehberger-cron_parser 0.3.0 → 0.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: d11c034aa656522a0e2ca5e145ca68f974b1b0eb9aeafad15797ee5a53d859f1
4
- data.tar.gz: 874e7abb865fa66511d7a407e7e0cc4ea0dfd8e8a637ff75225cffc9db5f0206
3
+ metadata.gz: 3be8924f48f35f97ea4d356f5368d7907cf23bda63af8af43c4b3776f1a47a69
4
+ data.tar.gz: 0d0284d3e84fe3b93db4911a30149333bf0faaba73f2857ec28ae95f83455509
5
5
  SHA512:
6
- metadata.gz: c8053224dd61f4defd352fbdf106351f995de7b16b6f10b610a40e99c47f577c0b27d241587aa74cd4299da2d7a4601c6879844eb63d68ce47dfcaa383ce5847
7
- data.tar.gz: f830772d6a686fec8dcf8f857a68b4be1f162bf70f0ebde4146f7228b44f5aadc18dbe567ce8570fcd4d5c5fa3125ab2ef56313978cec0320caa5b7796d458b5
6
+ metadata.gz: 4cf277261fcf00a553dc1defe27a24b74ace4d34f7760e5033d5b52dbbb2fa87bacb0a36b32e8847bd3af4e2d93381caf3fa17b8f5e6fa0953fc32a3105f2b01
7
+ data.tar.gz: 6e5f421543e3a2871f1b8e068f12dab5ebec5586ff18ee297dcbca94261cca57e931c72e00af468a783170462edd333939b1e1370d715a5770b32fb3f457f4fc
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-04-30
11
+
12
+ ### Added
13
+ - `Expression#count_in(from:, to:)` returns the number of times the expression matches within an inclusive time window — useful for capacity planning and alert tuning
14
+
10
15
  ## [0.3.0] - 2026-04-09
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -49,6 +49,15 @@ cron.matches?(Time.new(2026, 3, 22, 9, 0, 0)) # => true
49
49
  cron.matches?(Time.new(2026, 3, 22, 10, 0, 0)) # => false
50
50
  ```
51
51
 
52
+ ### Counting Occurrences in a Window
53
+
54
+ ```ruby
55
+ cron = Philiprehberger::CronParser.new('*/15 * * * *')
56
+ from = Time.new(2026, 4, 30, 9, 0, 0)
57
+ to = Time.new(2026, 4, 30, 10, 0, 0)
58
+ cron.count_in(from: from, to: to) # => 5
59
+ ```
60
+
52
61
  ### Human-Readable Description
53
62
 
54
63
  ```ruby
@@ -118,6 +127,7 @@ Philiprehberger::CronParser.new('0 9 * * MON-FRI') # named weekdays
118
127
  | `Expression#next(from:)` | Calculate the next matching time |
119
128
  | `Expression#prev(from:)` | Calculate the previous matching time |
120
129
  | `Expression#next_n(n, from:)` | Calculate the next N matching times |
130
+ | `Expression#count_in(from:, to:)` | Count occurrences within an inclusive `[from, to]` window |
121
131
  | `Expression#matches?(time)` | Check if a time matches the expression |
122
132
  | `Expression#human_readable` | Human-readable description of the expression |
123
133
  | `Expression#description` | Alias for `human_readable` |
@@ -106,6 +106,30 @@ module Philiprehberger
106
106
  results
107
107
  end
108
108
 
109
+ # Count occurrences within a time window [from, to].
110
+ #
111
+ # The window is inclusive on both ends; `from` is treated as the cursor's
112
+ # starting point so an exact match at `from` counts only if it lies on a
113
+ # minute boundary that the schedule fires on.
114
+ #
115
+ # @param from [Time] start of the window
116
+ # @param to [Time] end of the window
117
+ # @return [Integer] the count of occurrences in the window
118
+ # @raise [Error] if `to` is earlier than `from`
119
+ def count_in(from:, to:)
120
+ raise Error, '`to` must be greater than or equal to `from`' if to < from
121
+
122
+ count = 0
123
+ cursor = round_to_minute(from) - 60
124
+ loop do
125
+ cursor = self.next(from: cursor)
126
+ break if cursor > to
127
+
128
+ count += 1
129
+ end
130
+ count
131
+ end
132
+
109
133
  # Return a human-readable description of the expression
110
134
  #
111
135
  # @return [String]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module CronParser
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-cron_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-09 00:00:00.000000000 Z
11
+ date: 2026-05-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse standard 5-field cron expressions and calculate next/previous occurrences,
14
14
  match times against patterns, and generate human-readable descriptions.