neilgupta/Sherlock

Event start date resulting in arbitary date with out mentioning `am/pm`

Closed this issue ยท 4 comments

Hey @neilgupta Amazing lib! Thanks for working on it ๐Ÿ˜„ I was using it for vscode-remind-me. Here is the issue am having...

> Date()
'Thu May 03 2018 10:47:12 GMT+0530 (IST)'
> event = s.parse("testing at 10:50")
{ isAllDay: false,
  eventTitle: 'testing',
  startDate: { 2018-05-03T17:20:00.000Z hasMeridian: false },
  endDate: null }
>

As you can see... the current time is 10:47 Am and am creating the even for 10:50, If I don't mention AM it creating the start date to a arbitrary date. Is mentioning am and pm compulsory ?
But, I do noticed that in some cases it is working fine, thought I couldn't figure out the patter to nail down the issue. Let me know if you need more details! Thanks! ๐Ÿ™‚

The am/pm is not required but without it, Sherlock has to guess what you mean. In this case, it guesses PM because 10am would be too close to now and if you were legitimately scheduling an event, itโ€™s more likely you mean a future time. (The heuristic just checks if itโ€™s in the same hour or earlier I believe)

Sorry, accidentally hit comment before I was done... to continue my comment: Sherlock is returning the time in GMT (17:20GMT is 10:50PM IST), so itโ€™s not a random time, just a different time zone.

Hope that helps!

Hey @neilgupta Thanks for the explanation. I didn't noticed the GMT. Now I got it.
I understood that sherlock is trying to guess the event to be a later event than the current hour. Is it something I can configure ?

It's a little more complex than just enforcing the time is later. It tries to guess am or pm based on some hard-coded conditions. The exact logic being used is:

if (hour < 12 && (hour < 7 || hour <= time.getHours()))
          // meridian is not included, adjust any ambiguous times
          // if you type 3, it will default to 3pm
          // if you type 11 at 5am, it will default to am,
          // but if you type it at 2pm, it will default to pm
          hour += 12;

The easiest way to configure this logic is to add a Watson post-processor that changes the time based on your own rules. For example, if Watson gets 10:50PM but you want AM, you can just subtract 12 hours from the time before Sherlock returns it.