yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
Method GetRoundedMinimumShiftPatternDuration (
  Real minimumduration
) const as Real
{
  Description:
  [*
    Rounds up the given minimum duration in order to ensure that shift patterns are used until the end of the unit period that ends after 'minimumduration' is elapsed.
    For example: if the shift pattern starts in January, and the minimum duration is 61 days: round up the RHS to 31+28+31=90 days, to make sure that all 3 months are using the shift pattern. 
    Otherwise, January+March would be a valid solution because 31+31=62 (>61).
  *]
  TextBody:
  [*
    result := 0.0;
    nextperiod := this;
    
    while( result < minimumduration and not isnull( nextperiod ) )
    {
      result := result + nextperiod.Duration().HoursAsReal();
      nextperiod := guard( nextperiod.NextPlanningUnitPeriod().astype( UnitPeriodTime ), null( UnitPeriodTime ) );
    }
    
    // If the period is too close to the end of the horizon, we can't round up.
    result := maxvalue( result, minimumduration );
    
    return result;
  *]
}