How to limit time period to another period?

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật