dialogy icon indicating copy to clipboard operation
dialogy copied to clipboard

Duckling Plugin filters Time_entity whose Time_entity.value.hour == reftime.hour if datetime_filters is set.

Open keshav47 opened this issue 2 years ago • 0 comments

Describe the bug

Call reference_time: 21-03-22 17:24:34

(Turn 1) Bot: What day for booking? Person: tomorrow #Expected Entity: 22-03-22 00:00:00, Captured Entity:22-03-22 00:00:00 (Turn 2) Bot: What time? Person: Book it 5pm. #Expected Entity: 21-03-22 17:00:00, Captured Entity:""

Due to current logic here select_datetime(), when datetime_filters is set (either Past or Future), we filter out out 5pm entity if call is made between 17:00:01< reference time <17:59:59 on 21-03-22.

To Reproduce Steps to reproduce the behavior:

  1. Set one of the alternatives as "5pm"
  2. put reference_time in context anything between [17:00:01, 17:59:59]
  3. See error

Expected behavior Should get 5pm entity in turn 2. This can be sorted by doing comparison on hour and ignore time and seconds value completely.

reference_time = unix_ts_to_datetime(self.reference_time, timezone="Asia/Kolkata")
        reference_time = reference_time.replace(
        hour=reference_time.hour, minute=0, second=0, microsecond=0)
        
filtered_time_entities = [
            entity
            for entity in time_entities
            if operation(dt2timestamp(entity.get_value()), dt2timestamp(reference_time))
        ]

Adding the following logic should solve this issue.

keshav47 avatar Mar 21 '22 13:03 keshav47