@@ -211,25 +211,64 @@ impl TaskReminder {
211211
212212 RecurrenceInterval :: Monthly ( number) => {
213213 let mut t = last_recurrence. unwrap_or ( d. start ) ;
214- for _ in 0 ..=( i as u32 ) {
215- t = add_months ( t, * number as u32 ) ;
216- }
214+
215+ // If the task has a last recurrence, start adding unit from the first instance
216+ // Else (the task has not ocurred yet), start adding unit from the second instance
217+ let start = {
218+ if last_recurrence. is_some ( ) {
219+ 0
220+ } else {
221+ 1
222+ }
223+ } ;
224+
225+ // If it has already ocurred before or if i > 0, add the number of units
226+ if last_recurrence. is_some ( ) || i > 0 {
227+ for _ in start..=( i as u32 ) {
228+ t = add_months ( t, * number as u32 ) ;
229+ }
230+ } ;
231+
217232 t
218233 }
219234
220235 RecurrenceInterval :: Yearly ( number) => {
221236 let mut t = last_recurrence. unwrap_or ( d. start ) ;
222- for _ in 0 ..=( i as u32 ) {
223- t = add_months ( t, 12 * ( * number as u32 ) ) ;
224- }
237+
238+ let start = {
239+ if last_recurrence. is_some ( ) {
240+ 0
241+ } else {
242+ 1
243+ }
244+ } ;
245+
246+ if last_recurrence. is_some ( ) || i > 0 {
247+ for _ in start..=( i as u32 ) {
248+ t = add_months ( t, * number as u32 ) ;
249+ }
250+ } ;
251+
225252 t
226253 }
227254
228255 RecurrenceInterval :: Workdays ( number) => {
229256 let mut t = last_recurrence. unwrap_or ( d. start ) ;
230- for _ in 0 ..( i + 1 ) {
231- t = add_workdays ( t, * number) ;
232- }
257+
258+ let start = {
259+ if last_recurrence. is_some ( ) {
260+ 0
261+ } else {
262+ 1
263+ }
264+ } ;
265+
266+ if last_recurrence. is_some ( ) || i > 0 {
267+ for _ in start..=( i as u32 ) {
268+ t = add_workdays ( t, * number) ;
269+ }
270+ } ;
271+
233272 t
234273 }
235274 } ,
0 commit comments