400 ] ); } if ( $endDt <= $startDt ) { return new \WP_Error( 'invalid_datetime', __( 'The end time must be after the start time.', 'unsupervised-schedular' ), [ 'status' => 400 ] ); } if ( substr( $startDt, 0, 10 ) !== substr( $endDt, 0, 10 ) ) { return new \WP_Error( 'invalid_window', __( 'Availability must start and end on the same day. Use the weekly repeat to cover multiple weeks.', 'unsupervised-schedular' ), [ 'status' => 400 ] ); } // A slot may only be tied to an offering the instructor owns, so it can // never inherit another instructor's price or payment routing at booking. if ( $offeringId > 0 ) { $offering = $this->offerings->findById( $offeringId ); if ( null === $offering || $offering->instructorId !== $instructorId ) { return new \WP_Error( 'invalid_offering', __( 'That offering is not available.', 'unsupervised-schedular' ), [ 'status' => 400 ] ); } } $duration = $durationMinutes > 0 ? $durationMinutes : AvailabilitySlot::DEFAULT_DURATION_MINUTES; $window = new AvailabilitySlot( instructorId: $instructorId, startDt: $startDt, endDt: $endDt, durationMinutes: $duration, offeringId: $offeringId > 0 ? $offeringId : null, ); // The window is stored as lesson-length slots, so one that cannot fit a // single lesson would persist nothing at all. if ( [] === $window->splitByDuration() ) { return new \WP_Error( 'invalid_window', sprintf( /* translators: %d: the selected lesson length, in minutes. */ __( 'This window is shorter than the %d-minute lesson length, so it holds no bookable slots. Choose a shorter lesson length or a longer window.', 'unsupervised-schedular' ), $duration ), [ 'status' => 400 ] ); } return $window; } }