session_date . ' ' . $session->start_time, $timezone ); $end = \DateTimeImmutable::createFromFormat( '!Y-m-d H:i:s', $session->session_date . ' ' . $session->end_time, $timezone ); if ( ! $start || ! $end ) { return null; } return array( $start, $end ); } /** * Check-in is allowed from N minutes before the start until the end, unless the session is completed. * * @since 0.1.0 * * @param object $session Session row. * @param \DateTimeImmutable $now Now. * @param \DateTimeZone $timezone Site timezone. * @return bool */ public static function allowed( $session, \DateTimeImmutable $now, \DateTimeZone $timezone ): bool { $bounds = self::bounds( $session, $timezone ); if ( ! $bounds || 'completed' === $session->status ) { return false; } $open = $bounds[0]->modify( '-' . max( 0, (int) $session->checkin_before_minutes ) . ' minutes' ); return $now >= $open && $now <= $bounds[1]; } /** * Calling candidates is allowed between start and end while the session is neither paused nor completed. * * @since 0.1.0 * * @param object $session Session row. * @param \DateTimeImmutable $now Now. * @param \DateTimeZone $timezone Site timezone. * @return bool */ public static function interview_allowed( $session, \DateTimeImmutable $now, \DateTimeZone $timezone ): bool { $bounds = self::bounds( $session, $timezone ); return $bounds && $now >= $bounds[0] && $now <= $bounds[1] && ! in_array( $session->status, array( 'paused', 'completed' ), true ); } }