Quintiq file version 2.0 
 | 
#parent: #root 
 | 
StaticMethod GetStartOfNextMonth ( 
 | 
  DateTime datetime, 
 | 
  Number nrofrecurrent 
 | 
) const declarative remote as DateTime 
 | 
{ 
 | 
  Description: 
 | 
  [* 
 | 
    Return the start date of the next month for the given date and number of recurrent in month. 
 | 
    This method will return a exact date after a month from the date, e.g Given 15 Jan, this will return 15 Feb. 
 | 
  *] 
 | 
  TextBody: 
 | 
  [* 
 | 
    /* Only add the durationfromstart after loop to avoid exceeding the last day of next month: 
 | 
       eg. Adding 2 months to 31-Jan using GetStartOfNextMonth will return 
 | 
           the same day of targetted month or last day of month ie. 31-Mar 
 | 
    */ 
 | 
    newstartofmonth := datetime; 
 | 
    durationfromstart := datetime - datetime.StartOfMonth(); 
 | 
     
 | 
    // durationinday will retain the time of the day 
 | 
    durationinday := datetime - datetime.StartOfDay(); 
 | 
     
 | 
    for( reccurent := 1; reccurent <= nrofrecurrent; reccurent++ ) 
 | 
    { 
 | 
      newstartofmonth := newstartofmonth.StartOfNextMonth(); 
 | 
    } 
 | 
     
 | 
    /* Add durationinday to last day of the new month to avoid losing the  
 | 
       time of the day                                     */                              
 | 
    lastdayofnewmonth := newstartofmonth.StartOfNextMonth() - Duration::Days( 1 ) + durationinday; 
 | 
    newdate := minvalue( newstartofmonth + durationfromstart, lastdayofnewmonth ); 
 | 
     
 | 
    return newdate 
 | 
  *] 
 | 
} 
 |