I've set up a availability event type with hourly granularity. When using bat state facet only on available state with start/end dates including fraction of an hour i get invalid results.

An example:

- i've setup only a single unit, say A, for unit type Car
- i have already an event in "booked" (blocking) state from 2018-04-15 0:00 to 2018-04-16 12:30 for in the availability calendar of unit A
- i search for availability from 2018-04-16 12:00 to 2018-04-17 13:30

expected result:

An empty set

actual result:

1 unit of type Car (Unit A)

After some debugging i found that this behaviour come from the call to getMatchingUnits in bat_facet.module at line 77

$response = $calendar->getMatchingUnits($start_date, $end_date, $valid_states, $constraints, TRUE);

the last parameter (TRUE) makes the search using "intersection" of states of events found in date range with the "available" state instead of difference.

In the date range from 2018-04-16 12:00 to 2018-04-17 13:30 the states are two ["booked", "available"]. This is right since the resource is booked until 2018-04-16 12:30 and then available.

But intersection (AbstractCalendar, line 148)

array_intersect($current_states, $valid_states); 

returns "available" element since $current_states = ["booked", "available"] and $valid_states = ["available"].

This puts the unit in the "included" set but this resource is clearly not bookable in the requested range.

The solution, at least for this specific case, is to use difference instead of intersection by changing:

$response = $calendar->getMatchingUnits($start_date, $end_date, $valid_states, $constraints);

Probably could be useful to choose the search behaviour from Bat State facet setting page.

Attached patch only changes the line above.

Comments

maurizio.ganovelli created an issue. See original summary.

maurizio.ganovelli’s picture

Status: Active » Needs review
Swathi Nagella’s picture

Hi,

I have same problem I used the patch also still i have same problem.

maurizio.ganovelli’s picture

Hi, i'm using current latest dev (Commit 48123d2) with this patch and seems to work correctly. Are you using the same version?

Swathi Nagella’s picture

Ya I used latest dev version only.

maurizio.ganovelli’s picture

I've extensively tested the system with this patch and it always gives me back the expected results.
I found other issues on bat_facets but not related to OP.
I'm sorry that I can't help you further on this.

acrollet’s picture

This patch looks like the right thing to do - I've created a PR at https://github.com/Roomify/bat_drupal/pull/57 and am going to have a colleague review it. Thanks!

Swathi Nagella’s picture

StatusFileSize
new151.57 KB

Hi,
#1 you mention that your getting date with time in search availability view page, but i am not getting time filed even if i select hours .Please can anyone help me

maurizio.ganovelli’s picture

Hi, in my case i've done a form alter since i have a custom datepicker for date and a dropdown for time (limited to opening hours).

Swathi Nagella’s picture

Hi, kindly advise how you mange the time.

maurizio.ganovelli’s picture

I think it's better to file a new issue since this seems unrelated to OP.

  • nicola85 committed 11de0fe on 8.x-1.x authored by acrollet
    Issue #2962639 by maurizio.ganovelli: require unit to be in a valid...

acrollet credited nicola85.

acrollet’s picture

Status: Needs review » Fixed

committed, thanks for the contribution!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.