cron_calc 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +10 -11
- data/cron_calc.gemspec +1 -1
- data/lib/cron_calc/version.rb +1 -1
- data/lib/cron_calc.rb +7 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65bbd980a990785461ad8513755d5ef1effc8d14f4dac4205bf0381f4489bbcd
|
4
|
+
data.tar.gz: 116ac513ff00017a519997d1399748faa95284b2171e6f11c5097a25b10525ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70d5d114af61a0430a52b8ef0fc06caecc693fe8f632472814f4335543b038ba6c94565069f831ee7486a8633e015e8833c65b6f1ba2814832a7bb5e4352c9fb
|
7
|
+
data.tar.gz: cb5b23e742052e1b76035721214c28c2a9ce162b70d7c1d60bb308e378db36318c3e4ceac9e65b4a7dc779c1cc710109880f8b921f00580df77bf5f1cc8d3539
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -21,8 +21,8 @@ Now, you can use one of three methods `#in`, `#next`, `#last` to determine cron
|
|
21
21
|
|
22
22
|
### Using `#in`
|
23
23
|
|
24
|
-
Calculates cron job occurrences within a given time period
|
25
|
-
@param period [Range] The time period for which to calculate cron job occurrences
|
24
|
+
Calculates cron job occurrences within a given time period.\
|
25
|
+
@param period [Range] The time period for which to calculate cron job occurrences.\
|
26
26
|
@return [Array<Time>] An array of Time instances representing each occurrence.
|
27
27
|
|
28
28
|
```ruby
|
@@ -34,10 +34,10 @@ Calculates cron job occurrences within a given time period.
|
|
34
34
|
|
35
35
|
### Using `#next`
|
36
36
|
|
37
|
-
Calculates the next 'n' occurrences of the cron job from a given start time
|
38
|
-
@param count [Integer] The number of occurrences to calculate. Defaults to `1
|
39
|
-
@param period_start [Time] The start time from which to calculate occurrences. Defaults to `Time.now
|
40
|
-
@param max_years [Integer] The maximum number of years to consider for the period. Defaults to `5
|
37
|
+
Calculates the next 'n' occurrences of the cron job from a given start time.\
|
38
|
+
@param count [Integer] The number of occurrences to calculate. Defaults to `1`.\
|
39
|
+
@param period_start [Time] The start time from which to calculate occurrences. Defaults to `Time.now`.\
|
40
|
+
@param max_years [Integer] The maximum number of years to consider for the period. Defaults to `5`.\
|
41
41
|
@return [Array<Time>] An array of the next 'n' occurrences.
|
42
42
|
|
43
43
|
```ruby
|
@@ -53,10 +53,10 @@ Calculates the next 'n' occurrences of the cron job from a given start time.
|
|
53
53
|
|
54
54
|
### Using `#last`
|
55
55
|
|
56
|
-
Calculates the last 'n' occurrences of the cron job until a given end time
|
57
|
-
@param count [Integer] The number of past occurrences to calculate
|
58
|
-
@param period_end [Time] The end time until which to calculate occurrences
|
59
|
-
@param max_years [Integer] The maximum number of years to consider for the period
|
56
|
+
Calculates the last 'n' occurrences of the cron job until a given end time.\
|
57
|
+
@param count [Integer] The number of past occurrences to calculate.\
|
58
|
+
@param period_end [Time] The end time until which to calculate occurrences.\
|
59
|
+
@param max_years [Integer] The maximum number of years to consider for the period.\
|
60
60
|
@return [Array<Time>] An array of the last 'n' occurrences.
|
61
61
|
|
62
62
|
```ruby
|
@@ -69,7 +69,6 @@ Calculates the last 'n' occurrences of the cron job until a given end time.
|
|
69
69
|
|
70
70
|
## Unsupported features
|
71
71
|
|
72
|
-
- DOW (Day of Week) - always require *
|
73
72
|
- Named DOW and months (SUN-SAT, JAN-DEC)
|
74
73
|
- Joining characters , - /
|
75
74
|
- Predefined definitions (@yearly, @monthly, @weekly, @daily, @midnight, @hourly)
|
data/cron_calc.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ['jakubmizinski@gmail.com']
|
10
10
|
|
11
11
|
spec.summary = 'Calculates cron job occurrences'
|
12
|
-
spec.description = 'Calculates cron job occurrences within a specified period
|
12
|
+
spec.description = 'Calculates cron job occurrences within a specified period
|
13
13
|
or determines next/last "n" occurrences based on a specified time.'
|
14
14
|
spec.homepage = 'https://github.com/mizinsky/cron_calc'
|
15
15
|
spec.license = 'MIT'
|
data/lib/cron_calc/version.rb
CHANGED
data/lib/cron_calc.rb
CHANGED
@@ -21,7 +21,8 @@ module CronCalc
|
|
21
21
|
minutes: 0..59,
|
22
22
|
hours: 0..23,
|
23
23
|
days: 1..31,
|
24
|
-
months: 1..12
|
24
|
+
months: 1..12,
|
25
|
+
dows: 0..7
|
25
26
|
}.freeze
|
26
27
|
|
27
28
|
def initialize(cron_string)
|
@@ -68,12 +69,13 @@ module CronCalc
|
|
68
69
|
|
69
70
|
def occurrences(period, count = nil, reverse: false)
|
70
71
|
time_combinations = generate_time_combinations(period, reverse).lazy
|
72
|
+
wdays = parse_cron_part(:dows)
|
71
73
|
|
72
74
|
time_combinations.each_with_object([]) do |(year, month, day, hour, minute), occ|
|
73
75
|
break occ if count && occ.length == count
|
74
76
|
|
75
77
|
time = Time.new(year, month, day, hour, minute)
|
76
|
-
occ << time if Date.valid_date?(year, month, day) && period.include?(time)
|
78
|
+
occ << time if Date.valid_date?(year, month, day) && period.include?(time) && wdays.include?(time.wday)
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
@@ -92,7 +94,8 @@ module CronCalc
|
|
92
94
|
minutes: splitted[0],
|
93
95
|
hours: splitted[1],
|
94
96
|
days: splitted[2],
|
95
|
-
months: splitted[3]
|
97
|
+
months: splitted[3],
|
98
|
+
dows: splitted[4]
|
96
99
|
}
|
97
100
|
end
|
98
101
|
|
@@ -122,7 +125,7 @@ module CronCalc
|
|
122
125
|
|
123
126
|
def cron_string_valid?
|
124
127
|
# rubocop:disable Layout/LineLength
|
125
|
-
regex = %r{\A(\*|([0-5]?\d)(,([0-5]?\d))*|(\*/\d+)|(\d+-\d+)) (\*|([01]?\d|2[0-3])(,([01]?\d|2[0-3]))*|(\*/\d+)|(\d+-\d+)) (\*|([12]?\d|3[01])(,([12]?\d|3[01]))*|(\*/\d+)|(\d+-\d+)) (\*|([1-9]|1[0-2])(,([1-9]|1[0-2]))*|(\*/\d+)|(\d+-\d+))
|
128
|
+
regex = %r{\A(\*|([0-5]?\d)(,([0-5]?\d))*|(\*/\d+)|(\d+-\d+)) (\*|([01]?\d|2[0-3])(,([01]?\d|2[0-3]))*|(\*/\d+)|(\d+-\d+)) (\*|([12]?\d|3[01])(,([12]?\d|3[01]))*|(\*/\d+)|(\d+-\d+)) (\*|([1-9]|1[0-2])(,([1-9]|1[0-2]))*|(\*/\d+)|(\d+-\d+)) (\*|([0-6])(,([0-6]))*|(\*/[0-6]+)|([0-6]-[0-6]))\z}
|
126
129
|
# rubocop:enable Layout/LineLength
|
127
130
|
cron_string.match?(regex)
|
128
131
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cron_calc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Miziński
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
|
-
Calculates cron job occurrences within a specified period
|
14
|
+
Calculates cron job occurrences within a specified period
|
15
15
|
or determines next/last "n" occurrences based on a specified time.
|
16
16
|
email:
|
17
17
|
- jakubmizinski@gmail.com
|