chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
  *]
}