All pastes #453798 Raw Edit

Mine

public text v1 · immutable
·published 2007-04-23 06:06 UTC
rendered paste body
    public Date calculateReturnDate(Date issueDate) {
    
      Date returnDate;
      returnDate.Day = 0;
      returnDate.Month = 0;         //initialise
      returnDate.Year = 0;
      
      //months jan, march, may, july, august, october, december     ALL 31 DAYS
              //1      3    5      7     8      10        12
      //months april, june, september, november                     ALL 30 DAYS
              // 4     6       9         11
      //months february                                                 28 DAYS
             //   2
      
      if (((issueDate.Month == 1) || (issueDate.Month == 3) || (issueDate.Month == 5) || ((issueDate.Month > 6) && (issueDate.Month < 9)) || (issueDate.Month == 10) || (issueDate.Month == 12)) && ((issueDate.Day > 0) && (issueDate.Day <= 31))) {      
          // IF the month is any month with 31 DAYS... AND the issue date is not greater than month end...
          issueDate.Day = issueDate.Day + 5;    //then the return date is incremented by 5.
          if (issueDate.Day > 31) {             //if the new number is invalid
              issueDate.Day = (issueDate.Day - 31);        //then rollover..
              issueDate.Month = (issueDate.Month + 1);     //..and make sure to increase the month too
              if (issueDate.Month > 12) {                  //if we have created an illegal year..
                  issueDate.Month = 1;                     //..rollover
                  issueDate.Year = (issueDate.Year + 1);   //..and increment the year
              }
          } 
          returnDate = issueDate;     //sets return value                                
          
         // returnDate = (issueDate.Day = (issueDate.Day + 5) );                  
         // (issueDate.Day = (issueDate.Day + 5) );
        
      }     else if (((issueDate.Month == 4) || (issueDate.Month == 6) || (issueDate.Month == 9) || (issueDate.Month == 11)) && ((issueDate.Day > 0) && (issueDate.Day <= 30))) {
              issueDate.Day = issueDate.Day + 5;    //then the return date is incremented by 5.
              if (issueDate.Day > 30) {             //if the new number is invalid
                  issueDate.Day = (issueDate.Day - 30);        //then rollover..
                  issueDate.Month = (issueDate.Month + 1);     //..and make sure to increase the month too
              }                                                //a year check is NOT needed here, since we are only looking at months up to 11
              returnDate = issueDate;     //sets return value                                
            }   else if ((issueDate.Month == 2) && ((issueDate.Day > 0) && (issueDate.Day <=28))) {
                  issueDate.Day = issueDate.Day + 5;
                  returnDate = issueDate;
                }   else if ((issueDate.Day > 0) && (issueDate.Day <= 31)) {
                      issueDate.Day = issueDate.Day + 5;
                      returnDate = issueDate;
                    }   else {
                            System.out.println("Invalid issue day specified! (Less than 1 or greater than 31)");
                            returnDate.Day = -1;
                            returnDate.Month = -1;
                            returnDate.Year = -1;
                        }
      
      
        
    }