forked from ice-cube-ruby/ice_cube
-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for BYSETPOS #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3e221e4
Support BYSETPOS for MONTHLY AND YEARLY freq
408e0b0
Modernize BYSETPOS commit
nehresma 2b997af
Merge branch 'master' into bysetpos
chrisrbnelson 6acee08
Fix bugs
chrisrbnelson 0c5d72b
NEB-1737 Added pertinent RRULE test, fixed minor issue in another spec
32527ad
NEB-1737 Updating changelog
6a28df4
NEB-1737 Linted the code, added more bysetops tests
fa960dc
NEB-1737 Linted the code more
ec5e91f
NEB-1737 Updating missing require library in the test
184b06d
NEB-1737 Refined rspec tests
1f2e6df
NEB-1737 Refined rspec tests
d09b34d
NEB-1737 Refined rspec tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,5 +8,8 @@ | |
| /spec/reports/ | ||
| /tmp/ | ||
|
|
||
| # rubymine | ||
| .idea | ||
|
|
||
| # rspec failure tracking | ||
| .rspec_status | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| module IceCube | ||
| module Validations::MonthlyBySetPos | ||
| def by_set_pos(*by_set_pos) | ||
| return by_set_pos([by_set_pos]) if by_set_pos.is_a?(Integer) | ||
|
|
||
| unless by_set_pos.nil? || by_set_pos.is_a?(Array) | ||
| raise ArgumentError, "Expecting Array or nil value for count, got #{by_set_pos.inspect}" | ||
| end | ||
| by_set_pos.flatten! | ||
| by_set_pos.each do |set_pos| | ||
| unless (set_pos >= -366 && set_pos <= -1) || | ||
| (set_pos <= 366 && set_pos >= 1) | ||
| raise ArgumentError, "Expecting number in [-366, -1] or [1, 366], got #{set_pos} (#{by_set_pos})" | ||
| end | ||
| end | ||
|
|
||
| @by_set_pos = by_set_pos | ||
| replace_validations_for(:by_set_pos, by_set_pos && [Validation.new(by_set_pos, self)]) | ||
| self | ||
| end | ||
|
|
||
| class Validation | ||
| attr_reader :rule, :by_set_pos | ||
|
|
||
| def initialize(by_set_pos, rule) | ||
| @by_set_pos = by_set_pos | ||
| @rule = rule | ||
| end | ||
|
|
||
| def type | ||
| :day | ||
| end | ||
|
|
||
| def dst_adjust? | ||
| true | ||
| end | ||
|
|
||
| def validate(step_time, schedule) | ||
| start_of_month = TimeUtil.start_of_month step_time | ||
| end_of_month = TimeUtil.end_of_month step_time | ||
|
|
||
| new_schedule = IceCube::Schedule.new(TimeUtil.previous_month(step_time)) do |s| | ||
| s.add_recurrence_rule IceCube::Rule.from_hash(rule.to_hash.except(:by_set_pos, :count, :until)) | ||
| end | ||
|
|
||
| occurrences = new_schedule.occurrences_between(start_of_month, end_of_month) | ||
| index = occurrences.index(step_time) | ||
| if index.nil? | ||
| 1 | ||
| else | ||
| positive_set_pos = index + 1 | ||
| negative_set_pos = index - occurrences.length | ||
|
|
||
| if @by_set_pos.include?(positive_set_pos) || @by_set_pos.include?(negative_set_pos) | ||
| 0 | ||
| else | ||
| 1 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def build_s(builder) | ||
| builder.piece(:by_set_pos) << by_set_pos | ||
| end | ||
|
|
||
| def build_hash(builder) | ||
| builder[:by_set_pos] = by_set_pos | ||
| end | ||
|
|
||
| def build_ical(builder) | ||
| builder["BYSETPOS"] << by_set_pos | ||
| end | ||
|
|
||
| nil | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like upstream won't accept this code if it uses ActiveSupport, since they want to keep it pure ruby.
ice-cube-ruby#449 (comment)
ice-cube-ruby#449 (comment)
ice-cube-ruby#449 (comment)
So if we did want to push this upstream we might need to replace them with pure ruby, but since that PR is still getting updates maybe we won't need to. So we can keep ActiveSupport for now and wait for upstream to fix & merge their version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good rule. The only thing is that tech-debt can hide under the radar. But, still, you probably want the functionality first. So,
It would be nice to push this upstream, but we don't really need to. So, let's deal with that later too. 👍