add more options to .when pefer_past param

This commit is contained in:
Alex Ward
2018-04-15 19:22:56 +01:00
parent 771a2b6ce2
commit be2cd96132
+6 -2
View File
@@ -675,7 +675,7 @@ def now():
return MayaDT(epoch=epoch)
def when(string, timezone='UTC', prefer_past=False):
def when(string, timezone='UTC', prefer_past=None):
""""Returns a MayaDT instance for the human moment specified.
Powered by dateparser. Useful for scraping websites.
@@ -694,8 +694,12 @@ def when(string, timezone='UTC', prefer_past=False):
'RETURN_AS_TIMEZONE_AWARE': True,
'TO_TIMEZONE': 'UTC',
}
if prefer_past:
if prefer_past is False:
settings['PREFER_DATES_FROM'] = 'future'
if prefer_past is True:
settings['PREFER_DATES_FROM'] = 'past'
dt = dateparser.parse(string, settings=settings)
if dt is None:
raise ValueError('invalid datetime input specified.')