//@@author A0142102E
package seedu.tasklist.commons.util;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;

public class RecurringUtil {
	
	/**
	 * Updates the dates of a task based on its recurring frequency.
	 */
	public static Calendar updateRecurringDate(Calendar toUpdate, String frequency, int value) {
		if (!toUpdate.getTime().equals(new Date(0))) {
		    switch (frequency) {
		    case "daily": toUpdate.add(Calendar.DAY_OF_YEAR, value); break;
		    case "weekly": toUpdate.add(Calendar.WEEK_OF_YEAR, value); break;
		    case "monthly": toUpdate.add(Calendar.MONTH, value); break;
		    case "yearly": toUpdate.add(Calendar.YEAR, value); break;
		    }
		}
		return toUpdate;
	}
	
	/**
	 * Checks if the date of the task matches user requested date based on its recurring frequency.
	 */
	public static boolean recurringMatchesRequestedDate(Calendar task, String frequency, Calendar requested) {
	    if (!task.getTime().equals(new Date(0)) && !requested.getTime().equals(new Date (0))) {
	    	
	    	for (int i = 0; i < 100; i++) {
		    	Calendar first = (Calendar) task.clone();
	    		if (frequency.equals("daily")) {
	    			first.add(Calendar.DAY_OF_YEAR, i);
	    	    }
	    		else if (frequency.equals("weekly")) {
	    			first.add(Calendar.WEEK_OF_YEAR, i);
	    	    }
	    		else if (frequency.equals("monthly")) {
	    			first.add(Calendar.MONTH, i);
	    	    }
	    		else if (frequency.equals("yearly")) {
	    			first.add(Calendar.YEAR, i);
	    	    }
	    		if (DateUtils.isSameDay(first, requested)) {
	    			return true;
	    		}
	        }
	    }
	    return false;
	}
}
@@ -180,24 +180,33 @@
 gUtil %7B%0A
-%09%0A%09/**%0A%09
+    %0A    /**%0A    
  * Updat
@@ -254,38 +254,44 @@
 ring frequency.%0A
-%09 */%0A%09
+     */%0A    
 public static Ca
@@ -367,18 +367,24 @@
 alue) %7B%0A
-%09%09
+        
 if (!toU
@@ -422,22 +422,28 @@
 (0))) %7B%0A
-%09%09
+      
     
+  
 switch (
@@ -451,26 +451,36 @@
 requency) %7B%0A
-%09%09
+            
     case %22da
@@ -531,30 +531,40 @@
 ue); break;%0A
-%09%09
+          
     
+  
 case %22weekly
@@ -613,30 +613,40 @@
 ue); break;%0A
-%09%09
+          
     
+  
 case %22monthl
@@ -693,22 +693,32 @@
  break;%0A
-%09%09
+          
     
+  
 case %22ye
@@ -771,50 +771,80 @@
 ak;%0A
-%09%09    %7D%0A%09%09%7D%0A%09%09return toUpdate;%0A%09%7D%0A%09%0A%09/**%0A%09
+            %7D%0A        %7D%0A        return toUpdate;%0A    %7D%0A    %0A    /**%0A    
  * C
@@ -939,14 +939,20 @@
 cy.%0A
-%09 */%0A%09
+     */%0A    
 publ
@@ -1050,25 +1050,28 @@
 equested) %7B%0A
-%09
+    
     if (!tas
@@ -1154,21 +1154,33 @@
 ) %7B%0A
-%09
+        
     
-%09%0A%09
+%0A
     
-%09
+        
 for 
@@ -1211,15 +1211,24 @@
 ) %7B%0A
-%09%09
+   
     
-%09
+         
 Cale
@@ -1265,23 +1265,32 @@
 lone();%0A
-%09    %09%09
+                
 if (freq
@@ -1310,32 +1310,44 @@
 %22daily%22)) %7B%0A
-%09    %09%09%09
+                    
 first.add(Ca
@@ -1370,35 +1370,50 @@
 AR, i);%0A
-%09
+        
     
-%09
     %7D%0A
-%09
+            
     
-%09%09
 else if 
@@ -1439,32 +1439,44 @@
 weekly%22)) %7B%0A
-%09    %09%09%09
+                    
 first.add(Ca
@@ -1500,35 +1500,50 @@
 AR, i);%0A
-%09
+      
     
-%09
     
-%7D%0A%09
+  %7D%0A          
     
-%09%09
+  
 else if 
@@ -1570,32 +1570,44 @@
 onthly%22)) %7B%0A
-%09
     
-%09%09%09
+                
 first.add(Ca
@@ -1624,35 +1624,50 @@
 TH, i);%0A
-%09
+       
     
-%09
+ 
     %7D%0A
-%09    %09%09
+                
 else if 
@@ -1697,24 +1697,36 @@
 ly%22)) %7B%0A
-%09    %09%09%09
+                    
 first.ad
@@ -1750,27 +1750,42 @@
 i);%0A
-%09
+   
     
-%09
+     
     %7D%0A
-%09    %09%09
+                
 if (
@@ -1829,16 +1829,28 @@
 ) %7B%0A
-%09
+              
     
-%09%09%09
+  
 retu
@@ -1862,18 +1862,30 @@
 ue;%0A
-%09    %09%09%7D%0A%09
+                %7D%0A    
     
@@ -1894,16 +1894,22 @@
   %7D%0A
-%09
+    
     %7D%0A
-%09
+    
     
@@ -1926,8 +1926,11 @@
 se;%0A
-%09
+    
 %7D%0A%7D

Fix indentation