setTimezone( $zone ); switch ( $frequency ) { case self::WEEKLY: $ahead = ( $weekday - (int) $now->format( 'w' ) + 7 ) % 7; $candidate = $now->modify( '+' . $ahead . ' days' )->setTime( $hour, $minute, 0 ); if ( $candidate->getTimestamp() <= $from ) { $candidate = $candidate->modify( '+7 days' )->setTime( $hour, $minute, 0 ); } return $candidate->getTimestamp(); case self::MONTHLY: $first = $now->modify( 'first day of this month' ); for ( $i = 0; $i < 3; $i++ ) { $month = $first->modify( '+' . $i . ' months' ); $day = min( $monthday, (int) $month->format( 't' ) ); $candidate = $month->setDate( (int) $month->format( 'Y' ), (int) $month->format( 'n' ), $day )->setTime( $hour, $minute, 0 ); if ( $candidate->getTimestamp() > $from ) { return $candidate->getTimestamp(); } } return $from + 30 * 86400; // unreachable: three months always contain a later day. case self::DAILY: default: $candidate = $now->setTime( $hour, $minute, 0 ); if ( $candidate->getTimestamp() <= $from ) { $candidate = $candidate->modify( '+1 day' )->setTime( $hour, $minute, 0 ); } return $candidate->getTimestamp(); } } }