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
Quintiq file version 2.0
#parent: #root
Method GenerateOccurrencesWhenWindowChanged
{
  TextBody:
  [*
    // Update the CalendarTime after a potential change of the Start of the Window.
    timezone := this.GetTimeZone();
    this.CalendarTime( this.Start().AddAsPeriod( timezone, Duration::Days( this.History() ) ) );
    
    windowChanged := guard( this.StartDate() <> this.PreviousStartDate(), false )
                  or guard( this.EndDate()   <> this.PreviousEndDate(),   false );
    
    if( windowChanged )
    {
      // Let the Events generate their occurrences based on the changed calendar window.
      traverse( this, Event.LeadingParticipation, leadPart )
      {
        onlyWhenChanged := false;
        leadPart.UpdateCalendar( onlyWhenChanged );
      }
    
      // Also update the occurrences of the subscriptions to other events.
      // This is only necessary when there is (or was!) as difference between the window of the calendar and
      // the window of the calendar to which is subscribed.
      traverse( this.Subscriptions(), Elements, subscription )
      {
        eventCalendarStartDate := subscription.Event().Calendar().StartDate();
        eventCalendarEndDate   := subscription.Event().Calendar().EndDate();
        if(    eventCalendarStartDate <> this.StartDate()
            or eventCalendarStartDate <> this.PreviousStartDate()
            or eventCalendarEndDate   <> this.EndDate()
            or eventCalendarEndDate   <> this.PreviousEndDate() )
        {
          subscription.AlignOccurrences( this.PreviousStartDate(), this.PreviousEndDate() );
        }
      }
    
      // Update the previous dates for the next check.
      // This should only be done after updating the calendars, because during the update
      // the previous dates are required to determine if new time intervals should be generated.
      this.PreviousStartDate( this.StartDate() );
      this.PreviousEndDate(   this.EndDate()   );
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}