bear / parsedatetime

Parse human-readable date/time strings
Apache License 2.0
694 stars 105 forks source link

Small parsing issue with time #207

Open zefoo opened 7 years ago

zefoo commented 7 years ago

I have this function:

def get_time(value, timezone_string): cal = parsedatetime.Calendar() datetime_obj, parse_status = cal.parseDT(datetimeString=value, sourceTime=arrow.get().to(timezone_string).datetime, tzinfo=timezone(timezone_string)) if not parse_status: return None return datetime_obj

Look at these 3 differences (all processed in a few seconds)

comprehension.get_time('now', 'America/Los_Angeles') datetime.datetime(2017, 1, 7, 10, 53, 32, tzinfo=<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>)

comprehension.get_time('Jan 14 at 10am', 'America/Los_Angeles') datetime.datetime(2017, 1, 14, 10, 0, tzinfo=<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>)

comprehension.get_time('Jan 14 at 10', 'America/Los_Angeles') datetime.datetime(2017, 1, 14, 10, 53, 35, tzinfo=<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>)

It seems Jan 14 at 10am is recognized properly, but Jan 14 at 10 is not. It may introduce other issues if "10" is somehow parsed, this may be by design but I wanted to share nonetheless. If it is by design, let me know. Or perhaps there is a flag to parse a little more loosely so that 10 may be recognized.