forked from ice-cube-ruby/ice_cube
-
Notifications
You must be signed in to change notification settings - Fork 0
Added support for BYSETPOS #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
136faf0
Support BYSETPOS for MONTHLY AND YEARLY freq
84120b5
Modernize BYSETPOS commit
nehresma 115d5a8
address the spec DST sensitivity in .to_yaml round trips
nehresma b3042c6
update PR from feedback
nehresma 6dd602d
excluding until, not util
nehresma c70d7f6
remove no longer needed TimeUtil active_support require
nehresma 0f5c71a
fix interval use with bysetpos
nehresma 621bf3d
remove unneeded use of activesupport for date arithmetic
nehresma ee3171d
support for bysetpos with freq=weekly
nehresma 6a50aad
support for parsing rrules from ical that are very long and wrap
nehresma d7ea51e
dont require the wrapped line to be the last the ical string
nehresma 3da01b5
Support BYSETPOS for MONTHLY AND YEARLY freq
63e387d
Fix bugs
chrisrbnelson cf41565
NEB-1737 Added pertinent RRULE test, fixed minor issue in another spec
0df8ee0
NEB-1737 Updating changelog
021723c
NEB-1737 Linted the code, added more bysetops tests
424fab6
NEB-1737 Linted the code more
23f4cc2
NEB-1737 Updating missing require library in the test
cd1d753
NEB-1737 Refined rspec tests
860b74e
NEB-1737 Refined rspec tests
31cd8d2
NEB-1737 Refined rspec tests
d2f2c83
NEB-1731 Fully merged with latest PR-449
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
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,73 @@ | ||
| module IceCube | ||
| module Validations::MonthlyBySetPos | ||
| def by_set_pos(*by_set_pos) | ||
| by_set_pos.flatten! | ||
| by_set_pos.each do |set_pos| | ||
| unless (-366..366).cover?(set_pos) && set_pos != 0 | ||
| 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, [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, start_time) | ||
| start_of_month = TimeUtil.build_in_zone([step_time.year, step_time.month, 1, 0, 0, 0], step_time) | ||
| eom_date = Date.new(step_time.year, step_time.month, -1) | ||
| end_of_month = TimeUtil.build_in_zone([eom_date.year, eom_date.month, eom_date.day, 23, 59, 59], step_time) | ||
|
|
||
| # Needs to start on the first day of the month | ||
| new_schedule = IceCube::Schedule.new(IceCube::TimeUtil.build_in_zone([start_of_month.year, start_of_month.month, start_of_month.day, step_time.hour, step_time.min, step_time.sec], start_of_month)) 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.
Uh oh!
There was an error while loading. Please reload this page.