日期选择器的自然语言处理

Our date picker and conversion is a powerful feature. I’d love to see us make it simpler to add a date/time to a post. A common way this is done is through natural language processing. Apps like Fantastical on iOS have used this for years for date input.

Instead of fiddling with the mouse to input a date, you could type in something like:

  • monday at 2pm which would output the date and time to your timezone
  • next friday at 10am NZST which outputs the date/time next friday in NZST
  • 11am which outputs today’s date at 11am
  • 8/9 to 8/13 which outputs a date range.

This could either replace the modal shown by clicking the calendar icon in the composer with a textbox (and an advanced button which shows the existing modal contents) or a separate modal launched by a keyboard shortcut.

9 个赞

This library might help with implementation: GitHub - wanasit/chrono: A natural language date parser in Javascript

That said I suspect it would be a challenge to get robust language support for this.

The current fully supported languages are en , ja , and fr ( de and pt are partially supported). Other languages from v1 ( nl and zh ) are under development.


Also, another UX pattern to consider is automatically replacing date strings in the body of a post with Discourse date/time objects. Sort of like one-boxing but for dates. E.g. if I type “next monday at 2pm” in my post, it automatically converts that to 2021-08-17T18:00:00Z.

5 个赞

I really like this idea!

3 个赞

我很喜欢这个想法,你能给我展示一下你设想的 UI 模型吗?这正是这里所缺少的。

可能甚至不需要用户界面。帖子烘焙后,NLP 可以进行处理,返回到客户端并用一个简单的模态框进行确认:

找到 1 个日期。您想将其转换为动态时间戳吗?
- 星期二下午 2 点 --> [discourse date]

或者,也可以更简单。单击日历图标,而不是日期选择器,它会变成一个简单的文本框。

并且,类似于我们的邀请模态框,可以有一个用于高级控件的按钮,该按钮会显示我们现有的日期/时间/时区选择器,以获得更精细化的选项。

我猜这应该由 @j.jaffeux 来决定,不确定这是否符合我们目前的 UI?我也不确定普通人是否愿意输入这么多内容,尤其是在智能手机上?

这在谷歌日历中是有意义的,因为你可以在输入事件名称时执行此操作,例如,输入

“水管工”

而不是输入

“水管工 下午 3 点 - 下午 5 点”

但这很容易,因为我使用的是带键盘的设备。

我实际上觉得我们的模态框在桌面和移动设备上都很麻烦,这就是我最初提出这个功能的原因。在模态框中输入today at 11:31am比使用滚动轮或点击大型模态框要快得多。许多日历已经这样做了,这使得人们更容易理解。

1 个赞

在桌面端我同意。在智能手机上不同意,因为在智能手机上打字太痛苦了。也许这可以只在桌面端生效?

1 个赞

我个人对此没意见。

日期中有大量代码实际上已经完成了此操作,我们与 @daniel 一起完成了这项工作。

基本上,有三种方法可以解决此问题:

  • 一个更好的模态框
  • 某个命令
  • 文本解析

文本解析很棒,但它并不能解决所有问题,而且我们还必须使其适用于所有地区。但我同意我们可以启用对一小部分的支持。它基本上已经在这里了,我只需要完成/启用它。

5 个赞