chrono 0.5.0 → 0.6.0

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
2
  SHA256:
3
- metadata.gz: 046fa468703ffbd8c7c77b1767853c5db8e518c6affbc0b2a84d466cb15492b5
4
- data.tar.gz: 2128582a3bf2822dc3eab8cdf27e159fb4bd193ed896b4cea36309e4fec5516e
3
+ metadata.gz: 946e2892180dd9ae752e3883cd0d85de26697b48303dc46d6ef9083958faccaa
4
+ data.tar.gz: b7a7dae085130625666abe7ebcdf40e50fa5ebe040b1cea101410458fbd165ae
5
5
  SHA512:
6
- metadata.gz: 46dbbf74bd81f5f5177109660e85edb88fb65fcf561947ea924f0fe158e5c117fb9b91a9c9b8a8202d425f3e0e6fdb43ef506912ce4207ba0bb0e4cb5648ae23
7
- data.tar.gz: 5891051f8983853fbafb88e171bfdb315653e43be2165cbb837e52a705e1a6a3696f441eee41b0b9842cbe7b8f40fbf430625016fa77e1c172c4d2a8eb68b6cb
6
+ metadata.gz: 45245d747c9904409700776623301c7f2ab6b4c26f93a078f7b4d84221fa6549d441a51a939ead6f0ded5b979617b8c48f21027a594769f75faecd2d17190458
7
+ data.tar.gz: b148ea5a87ff74823c69d642f9b8e5af0630b2a0720ac92abf51a49b6856347b45fa79381d33acfe1404d8c5ba39024c230394731285923ebf898f06ed367ca5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.6.0
6
+
7
+ ### Added
8
+
9
+ - Add last-day-of-month syntax (thx @itkrt2y).
10
+
5
11
  ## 0.5.0
6
12
 
7
13
  ### Added
@@ -21,7 +21,7 @@ module Chrono
21
21
  fields.map(&:to_a).flatten.uniq.sort
22
22
  else
23
23
  validate!
24
- lower.step(upper, step).to_a.sort
24
+ wildcard? ? [] : lower.step(upper, step).to_a.sort
25
25
  end
26
26
  end
27
27
 
@@ -31,11 +31,21 @@ module Chrono
31
31
  source.gsub("*", "#{range.first}-#{range.last}")
32
32
  end
33
33
 
34
+ def wildcards
35
+ []
36
+ end
37
+
38
+ def wildcard?
39
+ wildcards.include?(source)
40
+ end
41
+
34
42
  def validate!
35
43
  unless match_data
36
44
  raise InvalidField.new('Unparsable field', source)
37
45
  end
38
46
 
47
+ return true if wildcard?
48
+
39
49
  if lower < range.begin || range.end < upper
40
50
  raise InvalidField.new('The field is out-of-range', source)
41
51
  end
@@ -68,7 +78,11 @@ module Chrono
68
78
  end
69
79
 
70
80
  def pattern
71
- %r<\A(\d+)(?:-(\d+))?(?:/(\d+))?\z>
81
+ ptn = %r<\A(\d+)(?:-(\d+))?(?:/(\d+))?\z>
82
+ if wildcards.any?
83
+ ptn = Regexp.union(ptn, *wildcards.map { |w| /\A#{w}\z/ })
84
+ end
85
+ ptn
72
86
  end
73
87
 
74
88
  def match_data
@@ -6,6 +6,10 @@ module Chrono
6
6
  def range
7
7
  1..31
8
8
  end
9
+
10
+ def wildcards
11
+ ['L']
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -48,7 +48,9 @@ module Chrono
48
48
  end
49
49
 
50
50
  def scheduled_in_this_day?
51
- if schedule.days?
51
+ if schedule.last_day_of_month?
52
+ time.day == time.end_of_month.day
53
+ elsif schedule.days?
52
54
  if schedule.wdays?
53
55
  schedule.days.include?(time.day) || schedule.wdays.include?(time.wday)
54
56
  else
@@ -46,6 +46,10 @@ module Chrono
46
46
  fields[4] != '*'
47
47
  end
48
48
 
49
+ def last_day_of_month?
50
+ fields[2] == 'L'
51
+ end
52
+
49
53
  private
50
54
 
51
55
  def fields
@@ -1,3 +1,3 @@
1
1
  module Chrono
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -25,6 +25,8 @@ describe Chrono::Iterator do
25
25
  "2000-01-01 00:00:00", "2000-01-03 00:00:00", "0 0 1,15 * 1",
26
26
  "2000-01-01 00:00:00", "2000-01-05 00:00:00", "0 0 5,15,25 * 5",
27
27
  "2000-02-29 00:00:01", "2004-02-29 00:00:00", "0 0 29 2 *",
28
+ "2000-01-01 00:00:00", "2000-01-31 00:00:00", "0 0 L * *",
29
+ "2000-01-31 00:00:00", "2000-02-29 00:00:00", "0 0 L * *",
28
30
  ].each_slice(3) do |from, to, source|
29
31
  it "ticks #{from} to #{to} by #{source}" do
30
32
  now = Time.parse(from)
@@ -124,6 +124,10 @@ describe Chrono::Schedule do
124
124
  let (:source){ '0 0 32 * *' }
125
125
  it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
126
126
  end
127
+ context 'last day of the month' do
128
+ let (:source){ '0 0 L * *' }
129
+ it { is_expected.to eq [] }
130
+ end
127
131
  end
128
132
 
129
133
  describe '#months' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrono
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-24 00:00:00.000000000 Z
11
+ date: 2023-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.4.0
69
- description:
69
+ description:
70
70
  email:
71
71
  - r7kamura@gmail.com
72
72
  executables: []
@@ -101,7 +101,7 @@ homepage: https://github.com/r7kamura/chrono
101
101
  licenses:
102
102
  - MIT
103
103
  metadata: {}
104
- post_install_message:
104
+ post_install_message:
105
105
  rdoc_options: []
106
106
  require_paths:
107
107
  - lib
@@ -116,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.1.4
120
- signing_key:
119
+ rubygems_version: 3.3.26
120
+ signing_key:
121
121
  specification_version: 4
122
122
  summary: Provides a chain of logics about chronology.
123
123
  test_files: