rrule 0.3.1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.rubocop.yml +28 -0
- data/.travis.yml +26 -1
- data/Appraisals +23 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +9 -0
- data/Rakefile +9 -3
- data/gemfiles/activesupport_2.3_LTS.gemfile +16 -0
- data/gemfiles/activesupport_3.gemfile +16 -0
- data/gemfiles/activesupport_4.gemfile +15 -0
- data/gemfiles/activesupport_5.gemfile +15 -0
- data/gemfiles/activesupport_6.gemfile +15 -0
- data/lib/rrule.rb +5 -0
- data/lib/rrule/context.rb +9 -7
- data/lib/rrule/filters/by_month.rb +2 -0
- data/lib/rrule/filters/by_month_day.rb +2 -0
- data/lib/rrule/filters/by_week_day.rb +5 -3
- data/lib/rrule/filters/by_week_number.rb +2 -0
- data/lib/rrule/filters/by_year_day.rb +3 -1
- data/lib/rrule/frequencies/daily.rb +2 -0
- data/lib/rrule/frequencies/frequency.rb +7 -13
- data/lib/rrule/frequencies/monthly.rb +2 -0
- data/lib/rrule/frequencies/simple_weekly.rb +14 -1
- data/lib/rrule/frequencies/weekly.rb +2 -0
- data/lib/rrule/frequencies/yearly.rb +2 -0
- data/lib/rrule/generators/all_occurrences.rb +4 -19
- data/lib/rrule/generators/by_set_position.rb +6 -15
- data/lib/rrule/generators/generator.rb +38 -0
- data/lib/rrule/rule.rb +52 -44
- data/lib/rrule/version.rb +5 -0
- data/lib/rrule/weekday.rb +4 -2
- data/rrule.gemspec +18 -11
- data/scripts/benchmark.rb +3 -1
- metadata +36 -50
- data/spec/context_spec.rb +0 -261
- data/spec/filters/by_month_day_spec.rb +0 -35
- data/spec/filters/by_month_spec.rb +0 -35
- data/spec/filters/by_week_day_spec.rb +0 -35
- data/spec/filters/by_week_number_spec.rb +0 -41
- data/spec/filters/by_year_day_spec.rb +0 -35
- data/spec/frequencies/daily_spec.rb +0 -62
- data/spec/frequencies/monthly_spec.rb +0 -63
- data/spec/frequencies/simple_weekly_spec.rb +0 -30
- data/spec/frequencies/weekly_spec.rb +0 -92
- data/spec/frequencies/yearly_spec.rb +0 -54
- data/spec/generators/all_occurrences_spec.rb +0 -44
- data/spec/generators/by_set_position_spec.rb +0 -39
- data/spec/rule_spec.rb +0 -2077
- data/spec/spec_helper.rb +0 -23
- data/spec/weekday_spec.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 75e4c7df763fb7f51c26dd5c904838cd711236c4f0c1b8903aaaa9fa8cb3a177
|
4
|
+
data.tar.gz: 8bd2ccc6326b7d839f53744091fed93000616e32af1305c8395fe129e9e5d294
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 744bc6a792d4ccaf944b6ed56c090387fe7c7dd87c79eae8f5c93fee299b47451d3834d6bfa7dd7dab062e7ae80fa12b0b333984d18e1579a9d2228ad4119543
|
7
|
+
data.tar.gz: 641c8c1f5c8320e4e17461a3dd040171c9a4a71cc6bb3cc1e70d3e16bb6ef8536ff54ace59447c7854a1504a86e0f140bbdc558bffe33515c79e802410c1ec0e
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
Exclude:
|
4
|
+
- 'gemfiles/**/*'
|
5
|
+
- Appraisals
|
6
|
+
|
7
|
+
Layout:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Lint/NonLocalExitFromIterator:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Naming:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
Style/MultilineBlockChain:
|
22
|
+
Enabled: false
|
23
|
+
Style/NumericPredicate:
|
24
|
+
Enabled: false
|
25
|
+
Style/RescueModifier:
|
26
|
+
Enabled: false
|
27
|
+
Style/TrailingCommaInArrayLiteral:
|
28
|
+
EnforcedStyleForMultiline: comma
|
data/.travis.yml
CHANGED
@@ -1,3 +1,28 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
2
3
|
rvm:
|
3
|
-
- 2.
|
4
|
+
- 2.6.5
|
5
|
+
- 2.7.0
|
6
|
+
- 3.0.0
|
7
|
+
|
8
|
+
gemfile:
|
9
|
+
- gemfiles/activesupport_2.3_LTS.gemfile
|
10
|
+
- gemfiles/activesupport_3.gemfile
|
11
|
+
- gemfiles/activesupport_4.gemfile
|
12
|
+
- gemfiles/activesupport_5.gemfile
|
13
|
+
- gemfiles/activesupport_6.gemfile
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
exclude:
|
17
|
+
- rvm: 2.7.0
|
18
|
+
gemfile: gemfiles/activesupport_3.gemfile
|
19
|
+
- rvm: 2.7.0
|
20
|
+
gemfile: gemfiles/activesupport_4.gemfile
|
21
|
+
- rvm: 3.0.0
|
22
|
+
gemfile: gemfiles/activesupport_3.gemfile
|
23
|
+
- rvm: 3.0.0
|
24
|
+
gemfile: gemfiles/activesupport_4.gemfile
|
25
|
+
|
26
|
+
before_install:
|
27
|
+
- yes | gem update --system --force
|
28
|
+
- gem install bundler
|
data/Appraisals
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise 'activesupport-2.3-LTS' do
|
4
|
+
gem 'rexml'
|
5
|
+
gem 'activesupport', '>= 2', git: 'https://github.com/makandra/rails.git', branch: '2-3-lts'
|
6
|
+
end
|
7
|
+
|
8
|
+
appraise 'activesupport-3' do
|
9
|
+
gem 'activesupport', '~> 3'
|
10
|
+
gem 'tzinfo', '~> 1.2'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'activesupport-4' do
|
14
|
+
gem 'activesupport', '~> 4'
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise 'activesupport-5' do
|
18
|
+
gem 'activesupport', '~> 5'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise 'activesupport-6' do
|
22
|
+
gem 'activesupport', '~> 6'
|
23
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
Change Log
|
2
2
|
==========
|
3
3
|
|
4
|
+
Version 0.4.3 *(2021-08-10)*
|
5
|
+
----------------------------
|
6
|
+
Adding support for multiple versions of ActiveSupport, up until at least ActiveSupport 6
|
7
|
+
Handle case where DTSTART is a date
|
8
|
+
Several bugfixes (fix weekday ordinal matching, BYDAY calculations with and without ordinals)
|
9
|
+
|
10
|
+
Version 0.4.2 *(2019-02-05)*
|
11
|
+
----------------------------
|
12
|
+
Truncate the floor_date option if it's less than the dtstart option
|
13
|
+
|
14
|
+
Version 0.4.1 *(2018-11-28)*
|
15
|
+
----------------------------
|
16
|
+
Fix bug in SimpleWeekly when ENV['TZ'] was not equal to time zone of rrule
|
17
|
+
|
18
|
+
|
4
19
|
Version 0.1.0 *(2017-06-06)*
|
5
20
|
----------------------------
|
6
21
|
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'rake'
|
5
|
+
require 'bundler/gem_tasks'
|
3
6
|
require 'rspec/core/rake_task'
|
4
|
-
require File.expand_path('
|
7
|
+
require File.expand_path('lib/rrule', __dir__)
|
5
8
|
|
6
9
|
RSpec::Core::RakeTask.new(:spec)
|
7
10
|
|
11
|
+
require 'rubocop/rake_task'
|
12
|
+
RuboCop::RakeTask.new
|
13
|
+
|
8
14
|
namespace :spec do
|
9
|
-
task :
|
15
|
+
task all: ['spec']
|
10
16
|
end
|
11
17
|
|
12
|
-
task :
|
18
|
+
task default: %w[spec:all rubocop]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry", "~> 0.12.2"
|
6
|
+
gem "rake"
|
7
|
+
gem "rspec", "~> 3.8"
|
8
|
+
gem "rubocop", "0.63.1"
|
9
|
+
gem "rexml"
|
10
|
+
gem "activesupport", ">= 2", git: "https://github.com/makandra/rails.git", branch: "2-3-lts"
|
11
|
+
|
12
|
+
platforms :mri do
|
13
|
+
gem "pry-byebug"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry", "~> 0.12.2"
|
6
|
+
gem "rake"
|
7
|
+
gem "rspec", "~> 3.8"
|
8
|
+
gem "rubocop", "0.63.1"
|
9
|
+
gem "activesupport", "~> 3"
|
10
|
+
gem "tzinfo", "~> 1.2"
|
11
|
+
|
12
|
+
platforms :mri do
|
13
|
+
gem "pry-byebug"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry", "~> 0.12.2"
|
6
|
+
gem "rake"
|
7
|
+
gem "rspec", "~> 3.8"
|
8
|
+
gem "rubocop", "0.63.1"
|
9
|
+
gem "activesupport", "~> 4"
|
10
|
+
|
11
|
+
platforms :mri do
|
12
|
+
gem "pry-byebug"
|
13
|
+
end
|
14
|
+
|
15
|
+
gemspec path: "../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry", "~> 0.12.2"
|
6
|
+
gem "rake"
|
7
|
+
gem "rspec", "~> 3.8"
|
8
|
+
gem "rubocop", "0.63.1"
|
9
|
+
gem "activesupport", "~> 5"
|
10
|
+
|
11
|
+
platforms :mri do
|
12
|
+
gem "pry-byebug"
|
13
|
+
end
|
14
|
+
|
15
|
+
gemspec path: "../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry", "~> 0.12.2"
|
6
|
+
gem "rake"
|
7
|
+
gem "rspec", "~> 3.8"
|
8
|
+
gem "rubocop", "0.63.1"
|
9
|
+
gem "activesupport", "~> 6"
|
10
|
+
|
11
|
+
platforms :mri do
|
12
|
+
gem "pry-byebug"
|
13
|
+
end
|
14
|
+
|
15
|
+
gemspec path: "../"
|
data/lib/rrule.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/all'
|
2
4
|
|
3
5
|
module RRule
|
@@ -18,9 +20,12 @@ module RRule
|
|
18
20
|
autoload :ByYearDay, 'rrule/filters/by_year_day'
|
19
21
|
autoload :ByMonthDay, 'rrule/filters/by_month_day'
|
20
22
|
|
23
|
+
autoload :Generator, 'rrule/generators/generator'
|
21
24
|
autoload :AllOccurrences, 'rrule/generators/all_occurrences'
|
22
25
|
autoload :BySetPosition, 'rrule/generators/by_set_position'
|
23
26
|
|
27
|
+
WEEKDAYS = %w[SU MO TU WE TH FR SA].freeze
|
28
|
+
|
24
29
|
def self.parse(rrule, **options)
|
25
30
|
Rule.new(rrule, **options)
|
26
31
|
end
|
data/lib/rrule/context.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RRule
|
2
4
|
class Context
|
3
5
|
attr_reader :options, :dtstart, :tz, :day_of_year_mask, :year
|
@@ -17,14 +19,14 @@ module RRule
|
|
17
19
|
possible_date_ranges = []
|
18
20
|
if options[:freq] == 'YEARLY'
|
19
21
|
if options[:bymonth]
|
20
|
-
options[:bymonth].each do |
|
21
|
-
possible_date_ranges.push(elapsed_days_in_year_by_month[(
|
22
|
+
options[:bymonth].each do |mon|
|
23
|
+
possible_date_ranges.push(elapsed_days_in_year_by_month[(mon - 1)..mon])
|
22
24
|
end
|
23
25
|
else
|
24
26
|
possible_date_ranges = [[0, year_length_in_days]]
|
25
27
|
end
|
26
28
|
elsif options[:freq] == 'MONTHLY'
|
27
|
-
possible_date_ranges = [elapsed_days_in_year_by_month[(month - 1)..
|
29
|
+
possible_date_ranges = [elapsed_days_in_year_by_month[(month - 1)..month]]
|
28
30
|
end
|
29
31
|
|
30
32
|
unless possible_date_ranges.empty?
|
@@ -39,10 +41,10 @@ module RRule
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
42
|
-
|
43
|
-
@last_year = year
|
44
|
-
@last_month = month
|
45
44
|
end
|
45
|
+
|
46
|
+
@last_year = year
|
47
|
+
@last_month = month
|
46
48
|
end
|
47
49
|
|
48
50
|
def year_length_in_days
|
@@ -82,7 +84,7 @@ module RRule
|
|
82
84
|
end
|
83
85
|
|
84
86
|
def negative_week_number_by_day_of_year
|
85
|
-
@
|
87
|
+
@negative_week_number_by_day_of_year ||= days_in_year.map { |day| day.cweek - Date.new(day.cwyear, 12, 28).cweek - 1 }
|
86
88
|
end
|
87
89
|
|
88
90
|
def elapsed_days_in_year_by_month
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RRule
|
2
4
|
class ByWeekDay
|
3
5
|
def initialize(weekdays, context)
|
@@ -6,17 +8,17 @@ module RRule
|
|
6
8
|
end
|
7
9
|
|
8
10
|
def reject?(i)
|
9
|
-
masked?(i)
|
11
|
+
masked?(i) && !matches_by_week_days?(i)
|
10
12
|
end
|
11
13
|
|
12
14
|
private
|
13
15
|
|
14
16
|
def masked?(i)
|
15
|
-
context.day_of_year_mask
|
17
|
+
context.day_of_year_mask.blank? || !context.day_of_year_mask[i]
|
16
18
|
end
|
17
19
|
|
18
20
|
def matches_by_week_days?(i)
|
19
|
-
by_week_days.
|
21
|
+
by_week_days.present? && by_week_days.include?(context.weekday_by_day_of_year[i])
|
20
22
|
end
|
21
23
|
|
22
24
|
attr_reader :by_week_days, :context
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RRule
|
2
4
|
class ByYearDay
|
3
5
|
def initialize(by_year_days, context)
|
@@ -6,7 +8,7 @@ module RRule
|
|
6
8
|
end
|
7
9
|
|
8
10
|
def reject?(i)
|
9
|
-
!by_year_days.empty? &&
|
11
|
+
!by_year_days.empty? &&
|
10
12
|
((i < context.year_length_in_days && !by_year_days.include?(i + 1) && !by_year_days.include?(i - context.year_length_in_days)) ||
|
11
13
|
(i >= context.year_length_in_days && !by_year_days.include?(i + 1 - context.year_length_in_days) && !by_year_days.include?(i - context.year_length_in_days - context.next_year_length_in_days)))
|
12
14
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RRule
|
2
4
|
class Frequency
|
3
5
|
attr_reader :current_date, :filters, :generator, :timeset
|
4
6
|
|
5
|
-
def initialize(context, filters, generator, timeset)
|
7
|
+
def initialize(context, filters, generator, timeset, start_date: nil)
|
6
8
|
@context = context
|
7
|
-
@current_date = context.dtstart
|
9
|
+
@current_date = start_date.presence || context.dtstart
|
8
10
|
@filters = filters
|
9
11
|
@generator = generator
|
10
12
|
@timeset = timeset
|
@@ -12,9 +14,7 @@ module RRule
|
|
12
14
|
|
13
15
|
def advance
|
14
16
|
@current_date = current_date.advance(advance_by).tap do |new_date|
|
15
|
-
unless same_month(current_date, new_date)
|
16
|
-
context.rebuild(new_date.year, new_date.month)
|
17
|
-
end
|
17
|
+
context.rebuild(new_date.year, new_date.month) unless same_month(current_date, new_date)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -32,10 +32,6 @@ module RRule
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def possible_days
|
36
|
-
fail NotImplementedError
|
37
|
-
end
|
38
|
-
|
39
35
|
def self.for_options(options)
|
40
36
|
case options[:freq]
|
41
37
|
when 'DAILY'
|
@@ -50,6 +46,8 @@ module RRule
|
|
50
46
|
Monthly
|
51
47
|
when 'YEARLY'
|
52
48
|
Yearly
|
49
|
+
else
|
50
|
+
raise InvalidRRule, 'Valid FREQ value is required'
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
@@ -60,9 +58,5 @@ module RRule
|
|
60
58
|
def same_month(first_date, second_date)
|
61
59
|
first_date.month == second_date.month && first_date.year == second_date.year
|
62
60
|
end
|
63
|
-
|
64
|
-
def advance_by
|
65
|
-
fail NotImplementedError
|
66
|
-
end
|
67
61
|
end
|
68
62
|
end
|