Skip to content
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

Added time to the recurring date parser #12

Merged
merged 1 commit into from
Jul 6, 2012
Merged
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
19 changes: 15 additions & 4 deletions app/models/usergroup.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Usergroup
attr_accessor :label_id, :domains, :recurring, :email, :mailing_list, :host, :twitter, :usergroup_email, :organizers, :location, :imprint, :other_usergroups

def parse_recurring(date)
def parse_recurring_date(date)
num, day = recurring.split
day = Date::DAYS_INTO_WEEK[day.to_sym] + 1
num = %w(first second third).index(num)
Expand All @@ -13,9 +13,20 @@ def parse_recurring(date)
end
end

def parse_recurring_time
num, day, time_string = recurring.split
if time_string.present?
hour, min = time_string.split(':')
t = Time.new(2012, 5, 1, hour.to_i, min.to_i)
else
t = Time.new(2012, 5, 1, 19, 0)
end
end

def next_event_date
d = parse_recurring(Date.today)
d = parse_recurring(Date.today.next_month) unless d.future?
Time.new(d.year, d.month, d.day, 19, 0)
d = parse_recurring_date(Date.today)
d = parse_recurring_date(Date.today.next_month) unless d.future?
t = parse_recurring_time
Time.new(d.year, d.month, d.day, t.hour, t.min)
end
end
29 changes: 26 additions & 3 deletions spec/models/usergroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,33 @@
end
end

it 'should include the parsed time, also' do
rughh.recurring = 'second wednesday 18:30'
rughh.next_event_date.hour.should eq(18)
rughh.next_event_date.min.should eq(30)
end
end

describe '#parse_recurring_date' do
it "should find the right wednesday" do
hackhb.parse_recurring(some_date).should eql(first_wednesday)
rughh.parse_recurring(some_date).should eql(second_wednesday)
colognerb.parse_recurring(some_date).should eql(third_wednesday)
hackhb.parse_recurring_date(some_date).should eql(first_wednesday)
rughh.parse_recurring_date(some_date).should eql(second_wednesday)
colognerb.parse_recurring_date(some_date).should eql(third_wednesday)
end
end

describe '#parse_recurring_time' do
it "should return a time with 19:00 as default" do
parsed_time = hackhb.parse_recurring_time
parsed_time.hour.should eql(19)
parsed_time.min.should eql(0)
end

it "should parse the recurring time" do
rughh.recurring = 'second wednesday 18:30'
parsed_time = rughh.parse_recurring_time
parsed_time.hour.should eql(18)
parsed_time.min.should eql(30)
end
end
end