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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Quintiq file version 2.0
#parent: #root
Method AlignOccurrences (
  Date oldStart_i,
  Date oldEnd_i
)
{
  TextBody:
  [*
    if( not this.IsRecurring() )
    {
      // It the occurrence overlaps with the calendar window,
      // then copy all (one) occurrences from the LeadingParticipation.
      if( this.Event().LeadingParticipation().StartTime() < this.Calendar().End() and
          this.Event().LeadingParticipation().EndTime()   > this.Calendar().Start() )
      {
        if( this.ExplicitTimeInterval( relsize ) = 0 )
        {
          this.CopyOccurrences();
        }
      }
      else  // Delete the occurrence if it is outside of the calendar window.
      {
        this.DeleteTimeIntervals( false );
      }
    }
    else
    {
      // Determine which occurrences should be removed, and which ones copied from the LeadingParticipation.
      period := this.GetRecurrencePeriod();
      start  := maxvalue( period.StartDate(), this.Calendar().StartDate() );
      end    := minvalue( period.EndDate(),   this.Calendar().EndDate()   );
        
      //info( this.Calendar().CalendarID() + "." + this.Event().Subject() );
      //info( "from :", oldStart_i, "-", oldEnd_i );
      //info( "  to :", start,      "-", end      );
    
      if( start <> oldStart_i or
          end   <> oldEnd_i )
      {
        if( start < oldStart_i )
        {
          // old :           |-----|
          // new :  |-----|
          if( end < oldStart_i )
          { //info( ">>> 1a" );
            this.RemoveOccurrencesAfter( end );
            this.CopyOccurrences( start, end );  
          }  
      
          // old :           |-----|
          // new :        |-----|
          else if( end <= oldEnd_i )
          { //info( ">>> 1b" );
            this.RemoveOccurrencesAfter( end );
            this.CopyOccurrences( start, oldStart_i - 1 );  
          }
      
          // old :           |-----|
          // new :        |-----------|
          else
          { //info( ">>> 1c" );
            this.CopyOccurrences( start,        oldStart_i - 1 );
            this.CopyOccurrences( oldEnd_i + 1, end            );  
          }
        }
        
        else if( start < oldEnd_i )
        { 
          // old :           |-----|
          // new :            |---|
          if( end < oldEnd_i )
          { //info( ">>> 2a" );
            this.RemoveOccurrencesBefore( start );
            this.RemoveOccurrencesAfter(   end  );  
          }
      
          // old :           |-----|
          // new :              |-----|
          else
          { //info( ">>> 2b" );
            this.RemoveOccurrencesBefore( start );
            this.CopyOccurrences( oldEnd_i + 1, end );  
          }
        }
        
        else
        { //info( ">>> 3" );
          // old :           |-----|
          // new :                   |-----|
          this.RemoveOccurrencesBefore( start );
          this.CopyOccurrences( start, end    );  
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}