modules/search/search.js
function _getTripSearchDates(db, datetime, preMins, postMins, callback) {

  // Get pre and post dates
  let preDateTime = datetime.clone().deltaMins(-1*preMins);
  let postDateTime = datetime.clone().deltaMins(postMins);

  // List of TripSearchDates to return
  let rtn = [];

  // Counters
  let done = 0;
  let count = 0;


  // ==== PRE AND POST DATES ARE SAME DAY ==== //
  if ( preDateTime.getDateInt() === postDateTime.getDateInt() ) {
    count = 1;

    // Get Effective Services
    CalendarTable.getServicesEffective(db, datetime.getDateInt(), function(err, services) {

      // Database Query Error
      if ( err ) {
        return callback(err);
      }

      // Create new TripSearchDate
      let tsd = new TripSearchDate(
        preDateTime.getDateInt(),
        preDateTime.getTimeSeconds(),
        postDateTime.getTimeSeconds(),
        services
      );

      // Add to List
      rtn.push(tsd);

      // Finish
      _finish();

    });

  }


  // ==== PRE AND POST DATES ARE DIFFERENT DAYS ==== //
  else {
    count = 2;

    // Get Effective Services for Prev Day
    CalendarTable.getServicesEffective(db, preDateTime.getDateInt(), function(err, services) {

      // Database Query Error
      if ( err ) {
        return callback(err);
      }

      // Create new TripSearchDate
      let tsd = new TripSearchDate(
        preDateTime.getDateInt(),
        preDateTime.getTimeSeconds(),
        postDateTime.getTimeSeconds() + 86400,
        services
      );

      // Add to List
      rtn.push(tsd);

      // Finish
      _finish();

    });


    // Get Effective Services for Post Day
    CalendarTable.getServicesEffective(db, postDateTime.getDateInt(), function(err, services) {

      // Database Query Error
      if ( err ) {
        return callback(err);
      }

      // Create new TripSearchDate
      let tsd = new TripSearchDate(
        postDateTime.getDateInt(),
        0,
        postDateTime.getTimeSeconds(),
        services
      );

      // Add to List
      rtn.push(tsd);

      // Finish
      _finish();

    });

  }


  // Finish processing a Trip Search Date
  function _finish() {
    done++;
    if ( done === count ) {
      return callback(null, rtn);
    }
  }

}
function _getTripSearchDates(db, datetime, preMins, postMins, callback) {

  // Get pre and post dates
  let preDateTime = datetime.clone().deltaMins(-1*preMins);
  let postDateTime = datetime.clone().deltaMins(postMins);

  // List of TripSearchDates to return
  let rtn = [];

  // Counters
  let done = 0;
  let count = 0;


  // ==== PRE AND POST DATES ARE SAME DAY ==== //
  if ( preDateTime.getDateInt() === postDateTime.getDateInt() ) {
    count = 1;

    // Get Effective Services
    CalendarTable.getServicesEffective(db, datetime.getDateInt(), function(err, services) {

      // Database Query Error
      if ( err ) {
        return callback(err);
      }

      // Create new TripSearchDate
      let tsd = new TripSearchDate(
        preDateTime.getDateInt(),
        preDateTime.getTimeSeconds(),
        postDateTime.getTimeSeconds(),
        services
      );

      // Add to List
      rtn.push(tsd);

      // Finish
      _finish();

    });

  }


  // ==== PRE AND POST DATES ARE DIFFERENT DAYS ==== //
  else {
    count = 2;

    // Get Effective Services for Prev Day
    CalendarTable.getServicesEffective(db, preDateTime.getDateInt(), function(err, services) {

      // Database Query Error
      if ( err ) {
        return callback(err);
      }

      // Create new TripSearchDate
      let tsd = new TripSearchDate(
        preDateTime.getDateInt(),
        preDateTime.getTimeSeconds(),
        postDateTime.getTimeSeconds() + 86400,
        services
      );

      // Add to List
      rtn.push(tsd);

      // Finish
      _finish();

    });


    // Get Effective Services for Post Day
    CalendarTable.getServicesEffective(db, postDateTime.getDateInt(), function(err, services) {

      // Database Query Error
      if ( err ) {
        return callback(err);
      }

      // Create new TripSearchDate
      let tsd = new TripSearchDate(
        postDateTime.getDateInt(),
        0,
        postDateTime.getTimeSeconds(),
        services
      );

      // Add to List
      rtn.push(tsd);

      // Finish
      _finish();

    });

  }


  // Finish processing a Trip Search Date
  function _finish() {
    done++;
    if ( done === count ) {
      return callback(null, rtn);
    }
  }

}
function _getTripSearchDates ( db , datetime , preMins , postMins , callback ) { // Get pre and post dates let preDateTime = datetime . clone ( ) . deltaMins ( - 1 * preMins ) ; let postDateTime = datetime . clone ( ) . deltaMins ( postMins ) ; // List of TripSearchDates to return let rtn = [ ] ; // Counters let done = 0 ; let count = 0 ; // ==== PRE AND POST DATES ARE SAME DAY ==== // if ( preDateTime . getDateInt ( ) === postDateTime . getDateInt ( ) ) { count = 1 ; // Get Effective Services CalendarTable . getServicesEffective ( db , datetime . getDateInt ( ) , function ( err , services ) { // Database Query Error if ( err ) { return callback ( err ) ; } // Create new TripSearchDate let tsd = new TripSearchDate ( preDateTime . getDateInt ( ) , preDateTime . getTimeSeconds ( ) , postDateTime . getTimeSeconds ( ) , services ) ; // Add to List rtn . push ( tsd ) ; // Finish _finish ( ) ; } ) ; } // ==== PRE AND POST DATES ARE DIFFERENT DAYS ==== // else { count = 2 ; // Get Effective Services for Prev Day CalendarTable . getServicesEffective ( db , preDateTime . getDateInt ( ) , function ( err , services ) { // Database Query Error if ( err ) { return callback ( err ) ; } // Create new TripSearchDate let tsd = new TripSearchDate ( preDateTime . getDateInt ( ) , preDateTime . getTimeSeconds ( ) , postDateTime . getTimeSeconds ( ) + 86400 , services ) ; // Add to List rtn . push ( tsd ) ; // Finish _finish ( ) ; } ) ; // Get Effective Services for Post Day CalendarTable . getServicesEffective ( db , postDateTime . getDateInt ( ) , function ( err , services ) { // Database Query Error if ( err ) { return callback ( err ) ; } // Create new TripSearchDate let tsd = new TripSearchDate ( postDateTime . getDateInt ( ) , 0 , postDateTime . getTimeSeconds ( ) , services ) ; // Add to List rtn . push ( tsd ) ; // Finish _finish ( ) ; } ) ; } // Finish processing a Trip Search Date function _finish ( ) { done ++ ; if ( done === count ) { return callback ( null , rtn ) ; } } }
Get the Trip Search Dates for the specified search range
@param {RightTrackDB} db The Right Track DB to query
@param {DateTime} datetime The Date/Time of the search starting point
@param {int} preMins The number of mins before the datetime to include
@param {int} postMins The number of mins after the datetime to include
@param {function} callback Callback function(err, tripSearchDates)
@private
Get the Trip Search Dates for the specified search range