• Hello!

    There’s a bug in wp-hotel-booking/includes/wphb-functions.php

    in function hb_count_nights_two_dates

    /**
     * Calculate the nights between to dates
     *
     * @param null $end
     * @param      $start
     *
     * @return float
     */
    if ( ! function_exists( 'hb_count_nights_two_dates' ) ) {
    	function hb_count_nights_two_dates( $end = null, $start ) {
    		if ( ! $end ) {
    			$end = time();
    		} else if ( is_numeric( $end ) ) {
    			$end = $end;
    		} else if ( is_string( $end ) ) {
    			$end = @strtotime( $end );
    		}
    
    		if ( is_numeric( $start ) ) {
    			$start = $start;
    		} else if ( is_string( $start ) ) {
    			$start = strtotime( $start );
    		}
    
    		$datediff = $end - $start;
    
    		return floor( $datediff / ( 60 * 60 * 24 ) );
    	}
    }

    If $start is false, the function counts nights since UNIX epoch start.

    Then it leads, for instance, in price calculations, to over 17700 excess iterations (for a current date). This chokes the script execution in some situations and makes it hang for several minutes.

    Proposed fix:

    		if ( is_numeric( $start ) ) {
    			$start = $start;
    		} else if ( is_string( $start ) ) {
    			$start = strtotime( $start );
    		}
    		else {
    			$start = $end;
    		}
    • This topic was modified 6 years, 2 months ago by liphtier.
Viewing 1 replies (of 1 total)
  • Plugin Contributor Thoa Kim

    (@thoakim)

    Hello

    Thanks for your feedback. We will review this point and improve the plugin. Really appreciate your contribution!

    Regards

Viewing 1 replies (of 1 total)
  • The topic ‘Bug in function hb_count_nights_two_dates’ is closed to new replies.