2009-08-11 61 views
5

分析是否有一个Python模块在Unix中解释模糊时间戳,如日期命令:模糊时间戳与Python

> date -d "2 minutes ago" 
Tue Aug 11 16:24:05 EST 2009 

我发现迄今dateutil.parser,从而未能在上面的例子中最接近的一次。

感谢

+1

你在这个例子中的“模糊”的想法是什么?你指定一个相对偏移的事实?或者这样做的语法(“2分钟前”)? “N - 00:02:00”也会模糊吗?还是因为你包含了“现在”这个不断变化的概念? – ThomasH 2009-08-11 08:15:36

回答

1

我已经涉足这一使用pyparsing - 你可以找到我的最新尝试here。它适用于这些测试案例:

today 
tomorrow 
yesterday 
in a couple of days 
a couple of days from now 
a couple of days from today 
in a day 
3 days ago 
3 days from now 
a day ago 
now 
10 minutes ago 
10 minutes from now 
in 10 minutes 
in a minute 
in a couple of minutes 
20 seconds ago 
in 30 seconds 
20 seconds before noon 
20 seconds before noon tomorrow 
noon 
midnight 
noon tomorrow