如何知道两个日期的最小周期,按不同的频率增加,重叠

to start im sorry for my bad english and i hope that you can understand my problem and finding a solution for it....

my problem is that i have two period

the first period:  dateStart1-dateEnd1
the secondperiod:  dateStart2-dateEnd2

for the first couple the frequence = 2 :

dte=dateStar1;dateEnd1>dte;dte+2week

for the second, the frequence = 3 :

dte=dateStar2;dateEnd2>dte;dte+3week

Exemple:

first period  2016-04-04 -> 2016-05-09 
frequence 2 weeks 2016-04-04 , 2016-04-18 , 2016-05-02

the second : 2016-04-11 -> 2016-05-09 
frequence 3 weeks 2016-04-11, 2016-05-02 

the two periods overlaps in 2016-05-02

my question in how to know the minimum number of weeks for the two period or dates to overlaps ? thank you

There is probably a better algorithm, but the only thing I can think of is a check on all available weeks for a period.

$result = [];
$current = clone $dateStart1;
while ($current < $dateEnd1) {
    // Calculate the difference betweenthe current date and dateStart2
    $diff = $current->diff($dateStart2);

    // Check if the difference is a multiple of the frequency, i.e. if the number of days is congruent to 7 times the frequency
    if ($diff->days % ($frequency2 * 7) == 0) {
        // If the anwser is yes, adds the current date to the list of overlapping dates.
        $result[] = clone $current;
    }

    // Get the next date possible for period 1 by adding $frequency1 weeks to the current date, and then try again till $dateEnd1 is reached.
    $current = $current->add(new \DateInterval('PT'.$frequency1.'W'););
}

return $result;

I haven't fully tested it, but this might at least help you to get on the rails.