Title: Bug in function hb_count_nights_two_dates
Last modified: September 8, 2018

---

# Bug in function hb_count_nights_two_dates

 *  [liphtier](https://wordpress.org/support/users/liphtier/)
 * (@liphtier)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/bug-in-function-hb_count_nights_two_dates/)
 * 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 7 years, 8 months ago by [liphtier](https://wordpress.org/support/users/liphtier/).

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [Thoa Kim](https://wordpress.org/support/users/thoakim/)
 * (@thoakim)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/bug-in-function-hb_count_nights_two_dates/#post-10675731)
 * 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.

 * ![](https://ps.w.org/wp-hotel-booking/assets/icon-256x256.png?rev=2442679)
 * [WP Hotel Booking](https://wordpress.org/plugins/wp-hotel-booking/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-hotel-booking/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-hotel-booking/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-hotel-booking/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-hotel-booking/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-hotel-booking/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Thoa Kim](https://wordpress.org/support/users/thoakim/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/bug-in-function-hb_count_nights_two_dates/#post-10675731)
 * Status: not resolved