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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Quintiq file version 2.0
#parent: #root
Method DoGenerateOccurrence (
  DateTime start_i,
  DateTime end_i,
  ExplicitTimeInterval firstOccurrence_i
) as Boolean
{
  Description: 'Determine if an occurrence should be generated.'
  TextBody:
  [*
    doGenerate := false;
    calendar   := this.Calendar();
    
    /* Special case #1: CalendarWindow moved forward and
     *                  the occurrence-to-be-generated starts before but ends after the new start of the window.
     *                  In this case, the occurrence should not be generated.
     *
     * The fact that this occurrence was not found indicates that it was explicitly deleted;
     * it should *not* be created now, but its deletion should be preserved.
     *
     * So: an occurrence can be generated when the CalendarWindow did not move forward,
     *     or when the occurrence starts after the start of the window.
     */
    startOfWindowMovedForward := calendar.StartDate() > calendar.PreviousStartDate();
    doGenerate := not startOfWindowMovedForward
               or start_i >= calendar.Start();
    
    if( doGenerate )
    {
      /* Special case #2 : CalendarWindow moved backward and
       *                   the occurrence-to-be-generated has overlap with the first already existing occurrence.
       *                   In this case, the occurrence should not be generated.
       *
       * This indicates that the first occurrence was modified and preserved,
       * and generating a new occurrence would result in a 'double' occurrence.
       *
       * So: an occurrence can be generated when the CalendarWindow did not move backward,
       *     or when there is no overlap with the first existing occurrence.
       */
      startOfWindowMovedBackward    := calendar.StartDate() < calendar.PreviousStartDate();
      hasOverlapWithFirstOccurrence := not isnull( firstOccurrence_i )
                                   and end_i   > firstOccurrence_i.Start()
                                   and start_i < firstOccurrence_i.End();
                                   
      doGenerate := not startOfWindowMovedBackward
                 or not hasOverlapWithFirstOccurrence;
    }
    
    return doGenerate;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}