serokell / tzbot

Timezone bot for Slack
Mozilla Public License 2.0
7 stars 2 forks source link

Discuss algorithm for choosing a month/year when omitted #72

Closed dcastro closed 1 year ago

dcastro commented 1 year ago

Clarification and motivation

In tzbot, we have many instances where the sender supplies partial information and we have to infer the rest. Some examples (there may be more I'm forgetting):

  1. "1am": the user supplied the time, but not the date.
  2. "1am on wednesday": the user supplied the time and day of the week, but they didn't specify which week.
  3. "1am on the 12th": the user supplied the time and day of the month, but not the month or year.
  4. "1am on March 12th": the user supplied the time, day of the month, and month, but not the year.

In the first 2 cases, we use a simple and easy to predict algorithm:

  1. "1am" is interpreted as 1am of the current day; unless that time is already in the past, in which case we infer they must mean 1am the next day.
  2. "1am on wednesday" is interpreted as 1am of the current day if today is wednesday; if it's not, then we infer it must mean 1am the next wednesday.

In other words, we always try to infer a point of time in the future. We use today's date, but if the time has already passed, we use the next suitable date in the nearest future.

In the last 2 cases though, we use a more complex algorithm:

https://github.com/serokell/tzbot/blob/635077e77d6c85ab9c1711076aa1d5970444e7aa/src/TzBot/TimeReference.hs#L169-L183

https://github.com/serokell/tzbot/blob/635077e77d6c85ab9c1711076aa1d5970444e7aa/src/TzBot/TimeReference.hs#L199-L204

I personally think we should use the same algorithm we use in the first two cases in the last two as well. It has the benefit of being easy to predict for users. Over time, as they use the bot, it'll be relatively easy to notice the pattern, so they'll realize they have to be more specific when they want to refer to a moment in the past.

Right now, it's not easy for users to predict what the bot will infer. As I write this, on the 14th Feb:

So I propose we use the simpler algorithm in all cases.

Acceptance criteria

dcastro commented 1 year ago

/cc @YuriRomanowski, let me know what you think.

YuriRomanowski commented 1 year ago

Counterexamples, on the 14th Feb:

When implementing those functions, I concluded that users do not usually use timestamps for very far future dates, and decided to infer past days sometimes. Hence the algorithms.

dcastro commented 1 year ago

Fair enough! Let's keep the current behavior then.