Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 44 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,47 @@ PATH
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.13)
activesupport (= 3.2.13)
builder (~> 3.0.0)
activerecord (3.2.13)
activemodel (= 3.2.13)
activesupport (= 3.2.13)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.4)
coderay (1.0.9)
diff-lcs (1.2.4)
i18n (0.6.1)
ice_cube (0.10.0)
method_source (0.8.1)
multi_json (1.7.3)
pry (0.9.12.1)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
rake (10.0.4)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
slop (3.4.4)
sqlite3 (1.3.7)
tzinfo (0.3.37)
activemodel (5.2.3)
activesupport (= 5.2.3)
activerecord (5.2.3)
activemodel (= 5.2.3)
activesupport (= 5.2.3)
arel (>= 9.0)
activesupport (5.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (9.0.0)
coderay (1.1.2)
concurrent-ruby (1.1.5)
diff-lcs (1.3)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
ice_cube (0.16.3)
method_source (0.9.2)
minitest (5.11.3)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rake (12.3.2)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
sqlite3 (1.4.1)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)

PLATFORMS
ruby
Expand All @@ -55,3 +61,6 @@ DEPENDENCIES
rspec
schedule_attributes!
sqlite3

BUNDLED WITH
1.17.3
4 changes: 2 additions & 2 deletions lib/schedule_attributes/extensions/ice_cube.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class IceCube::Rule
def ==(other)
to_hash == other.to_hash
to_hash == other&.to_hash
end
end

class IceCube::Schedule
def ==(other)
to_hash == other.to_hash
to_hash == other&.to_hash
end
end
37 changes: 33 additions & 4 deletions lib/schedule_attributes/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,44 @@ def start_time
def end_time
return nil if @params[:all_day]
return nil unless @params[:end_time].present?
parse_date_time(date_input, @params[:end_time])
parse_date_time(end_time_date, @params[:end_time])
end

# if end_time < start_time, the schedule occurs over night
def end_time_date
return date_input unless @params[:start_time].present?
return nil if @params[:all_day]
return nil unless @params[:end_time].present?
parse_date_time(date_input, @params[:end_time]) <= start_time ? (Time.parse(date_input) + 1.day).strftime('%Y-%m-%d') : date_input
end

def start_date
parse_date_time(@params[:start_date]) if @params[:start_date]
if @params[:start_date]
parse_date_time(@params[:start_date], @params[:start_time])
elsif @params[:start_time] && !time_only?(@params[:start_time])
parse_date_time(@params[:start_time])
elsif start_time
start_time
else
parse_date_time(@params[:start_time])
end
end

def end_date
parse_date_time(@params[:end_date], @params[:start_time]) if @params[:end_date]
if @params[:end_date]
parse_date_time(@params[:end_date], @params[:end_time] || @params[:start_time])
elsif @params[:end_time] && !time_only?(@params[:end_time])
parse_date_time(@params[:end_time])
elsif end_time
end_time
else
parse_date_time(@params[:end_time])
end
end

def ends?
@params[:end_date].present? && @params[:ends] != "never"
return false if @params[:ends] == "never"
@params[:end_date].present? || @params[:end_time].present?
end

def dates
Expand All @@ -147,5 +172,9 @@ def parse_date_time(date, time=nil)
return if date_time_parts.empty?
TimeHelpers.parse_in_zone(date_time_parts.join(' '))
end

def time_only?(string)
!!(string.strip =~ /\d{1,2}\:\d{2}/)
end
end
end
4 changes: 2 additions & 2 deletions lib/schedule_attributes/time_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module TimeHelpers
def self.parse_in_zone(str)
if Time.respond_to?(:zone) && Time.zone
return str.in_time_zone if str.is_a?(Time)
str.is_a?(Date) ? str.to_time_in_current_zone : Time.zone.parse(str)
str.is_a?(Date) ? str.in_time_zone : Time.zone.parse(str)
else
return str if str.is_a?(Time)
Time.parse(str)
Expand All @@ -12,7 +12,7 @@ def self.parse_in_zone(str)

def self.today
if Time.respond_to?(:zone) && Time.zone
Date.current.to_time_in_current_zone
Date.current.in_time_zone
else
Date.today.to_time
end
Expand Down
6 changes: 3 additions & 3 deletions spec/active_record_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe CustomScheduledActiveRecordModel do

it "should have a default schedule" do
subject.my_schedule.should == hourly
expect(subject.my_schedule).to eq(hourly)
end

def hourly
Expand All @@ -20,7 +20,7 @@ def hourly
alias :model :subject

it "should have a default schedule" do
subject.schedule.should be_a IceCube::Schedule
expect(subject.schedule).to be_a IceCube::Schedule
end


Expand All @@ -38,7 +38,7 @@ def hourly
expected = IceCube::Schedule.new(Time.local(2013, 2, 26)) do |s|
s.rrule IceCube::Rule.daily(3).until(Time.local(2016, 7, 7))
end
model.schedule.should == expected
expect(model.schedule).to eq(expected)
end
end

Expand Down
11 changes: 7 additions & 4 deletions spec/schedule_attributes/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
describe ".configure" do
it "yields a configuration instance" do
ScheduleAttributes.configure do |config|
config.should be_a ScheduleAttributes::Configuration
expect(config).to be_a ScheduleAttributes::Configuration
end
end

it "returns a configuration instance" do
ScheduleAttributes.configure.should be_a ScheduleAttributes::Configuration
expect(ScheduleAttributes.configure).to be_a ScheduleAttributes::Configuration
end
end
end

describe ScheduleAttributes::Configuration do
its(:time_format) { should == '%H:%M' }
describe '#time_format' do
subject { super().time_format }
it { is_expected.to eq('%H:%M') }
end

it "#time_format is settable" do
subject.time_format = '%l:%M %P'
subject.time_format.should == '%l:%M %P'
expect(subject.time_format).to eq('%l:%M %P')
end
end
Loading