Quintiq file version 2.0 
 | 
#parent: #root 
 | 
StaticMethod GetAlignedStart ( 
 | 
  DateTime currentstart, 
 | 
  DateTime newstartofplanning, 
 | 
  String timeunit, 
 | 
  Number nroftimeunit 
 | 
) as DateTime 
 | 
{ 
 | 
  Description: 'Return the new aligned date time with the given date time, time unit, nr of time unit and if it is forward or backward.' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // DWE2 May-11-2016 (created) 
 | 
    newdate := currentstart; 
 | 
     
 | 
    if( currentstart < newstartofplanning ) 
 | 
    { 
 | 
      while( newstartofplanning >= newdate ) 
 | 
      { 
 | 
        newdate := PeriodSpecification_MP::GetStartOfNextPeriod( newdate, timeunit, nroftimeunit ); 
 | 
      } 
 | 
     
 | 
      /* Need to move one period a head because the end of next period not always align with the new start date 
 | 
         E.g: Weeks vs Month, Start of planning, period alignment 1 Jan 2016 
 | 
         when we go through this loop, the loop will exit @ 5 Feb, this is because the start of next from 22 Jan is 29 Jan which is < than the newdate 
 | 
         Do not offset the date because we wont know whats the duration we need to offset 
 | 
      */ 
 | 
      newdate := PeriodSpecification_MP::GetStartOfPreviousPeriod( newdate.Date(), timeunit, nroftimeunit ); 
 | 
    } 
 | 
    else 
 | 
    { 
 | 
      while( newdate > newstartofplanning ) 
 | 
      { 
 | 
        newdate := PeriodSpecification_MP::GetStartOfPreviousPeriod( newdate.Date(), timeunit, nroftimeunit ); 
 | 
      } 
 | 
    } 
 | 
     
 | 
    return newdate; 
 | 
  *] 
 | 
} 
 |