For a project planning I have an initial period, lets call it PPStart-PPEnd
.
The planning is associated with a project. This also has a period PrjStart-PrjEnd
. PrjStart and PrjEnd are fixed, and can be unbound, i.e. the project start time or end time are not defined.
PPStart-PPEnd
should be adjusted so that people can only plan tasks in the valid project period. If that changes the duration, fine.
How do I efficiently limit PPStart-PPEnd
to PrjStart-PrjEnd
without having to go over all the possible combinations?
Maybe first detecting overlapping periods is a good start?
4 examples on a time axis ([– = bound, <– = unbound):
Project planning period:
[---PPStart-PPEnd---]
Project periods relative to ppp:
[---PrjStart-PrjEnd---] PPStart should be set to PrjStart, PPEnd unchanged
[---PrjStart-PrjEnd---] PPEnd should be set to PrjEnd, PPStart unchanged
[---PrjStart-PrjEnd-------------------> No adjustments
[---PrjStart-PrjEnd---] PPStart should be set to PrjStart and PPEnd to PrjEnd.
Cases like that last one make it complex.
5
If I understand your question correctly, you’re asking how you can adjust time intervals without having a tangle of if elseifs checking every possibility, am I right?
You can simplify things a bit by looking at one date at a time. In other words, don’t think in terms of checking if the start and end are outside the interval and if so, adjust both start and end.
Think of it rather in terms of:
Is both PrjStart and PrjEnd less than PPStart or is both PrjStart and PrjEnd greater than PPEnd? If yes, update both values.
Is PPStart not open-ended and less than PrjStart? If yes, then update PPStart to the value of PrjStart.
Is PPEnd not open-ended and greater than PrjEnd? If yes, then update PPEnd to the value of PrjEnd.
You’ll find that this satisfies all your conditions. If you try to handle it in terms of both PPStart and PPEnd, then you’ll have to cover every combination of these two dates with those of PrjStart and PrjEnd. The reason you’d have to check if both are over or under is because only in that instance do the latter two rules differ. In other words, if they overlap, you’re willing to shorten the planning period whereas when there is no overlap, the entire period is set.
Answering my own question. There was no ‘definitive’ ‘smart’ answer yet.
The best I can come up with is still a bunch of if statements – meaning it does not satisfy my own question, but at least it’s a complete schema covering all cases.
Schematically, these are what has to happen (first line is the proposed project plan period that has to be adjusted):
******************** Suggested PPStart-PPEnd = 1 year
[--------] [--------] PPStart := PrjStart PPEnd := PrjEnd
[--------] PPEnd := PrjEnd
[--------] PPStart := PrjStart PPEnd unchanged, but let's take PPEnd := PPStart + 1 year
[--------] PPStart := PrjStart PPEnd := PrjEnd
[-------------------------] -nothing-
<--------] PPEnd := PrjEnd
[--------> PPStart := PrjStart PPEnd unchanged, but let's take PPEnd := PPStart + 1 year
<-------------------------> -nothing-
<-------------------------] -nothing-
[-------------------------> -nothing-
And then what’s left is putting the if statements in a smart order