在 Ubuntu 12.04 上的 Python 2.7 上使用 Bear 的 parsedatetime 库。当传入一个包含字符但没有有效日期(或时间)的字符串时,parse() 函数有时会返回一个有效的日期/时间。
提交第 48 期后,看起来 parsedatetime 真的不想要一个没有日期/时间的字符串。
那么,关于预处理器确定字符串是否包含有效日期的布尔值的想法?
参考链接: https ://github.com/bear/parsedatetime/ https://code.google.com/p/parsedatetime/issues/detail?id=48
注意:在第 48 期中,我不恰当地调用了 parseDateText()。我已经确认 parse() 存在相同的操作。
非常感谢任何帮助。
编辑:示例代码。
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import parsedatetime as pdt
>>> c = pdt.Constants()
>>> c.BirthdayEpoc = 80
>>> p = pdt.Calendar(c)
>>> print p.parse("Mary had a little lamb.")
((2014, 3, 1, 20, 53, 56, 6, 69, 1), 1)
>>> print p.parse("foo bar")
(time.struct_time(tm_year=2013, tm_mon=3, tm_mday=10, tm_hour=20, tm_min=54, tm_sec=6, tm_wday=6, tm_yday=69, tm_isdst=1), 0)
>>> print p.parse("March 12th, 2013")
((2013, 3, 12, 20, 54, 34, 6, 69, 1), 1)
>>>