Skip to content

Commit

Permalink
Monthly recurring tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Nov 27, 2010
1 parent 0ec2e03 commit f329d1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 15 additions & 0 deletions lib/xtdo.rb
Expand Up @@ -134,6 +134,21 @@ def self.calculate_starting_day(date, number, period, start = nil)
if days.index(start)
(days.index(start) - date.wday) % 7 + (number - 1) * 7
end
when 'm' then
start = start.to_i
if start > 0
year = date.year
if start.to_i <= date.day
month = date.month + 1
if month > 12
month = 1
year += 1
end
else
month = date.month
end
Date.new(year, month, start.to_i) - date
end
end
if adjust
if adjust == 0
Expand Down
13 changes: 7 additions & 6 deletions spec/recurring_spec.rb
Expand Up @@ -16,9 +16,13 @@
it { Xtdo.calculate_starting_day(today, 1, 'w', 'tue').should == today + 1}
it { Xtdo.calculate_starting_day(today, 1, 'w', 'sun').should == today + 6}
it { Xtdo.calculate_starting_day(today, 1, 'w', '0').should == nil }
it { Xtdo.calculate_starting_day(today, 1, 'm', '1').should == Date.new(2010,12,1)}
it { Xtdo.calculate_starting_day(today, 1, 'm', '22').should == Date.new(2010,12,22)}
it { Xtdo.calculate_starting_day(today, 1, 'm', '23').should == Date.new(2010,11,23)}
it { Xtdo.calculate_starting_day(today, 1, 'm', '0').should == nil }
end

let(:today) { Date.new(2010,11,17) } # Monday
let(:today) { Date.new(2010,11,17) } # Monday
scenario 'daily' do

time_travel today
Expand Down Expand Up @@ -67,19 +71,16 @@
end

scenario 'monthly' do
time_travel today
t('r a 1m,3 T1')

time_travel Date.new(2010,11,3)
time_travel Date.new(2010,12,3)
t('l').should have_task('T1')
t('b 1 T1')
t('l').should_not have_task('T1')
t('d T1')
t('l').should_not have_task('T1')

time_travel Date.new(2010,12,3)
t('l').should have_task('T1')
t('d T1')

time_travel Date.new(2011,1,4)
t('l').should have_task('T1')
end
Expand Down

0 comments on commit f329d1f

Please sign in to comment.