mirror of
https://github.com/kennethreitz/maya.git
synced 2026-06-05 23:00:18 +00:00
update .when to use prefer_dates_from to align with dateparser
This commit is contained in:
+2
-6
@@ -675,7 +675,7 @@ def now():
|
||||
return MayaDT(epoch=epoch)
|
||||
|
||||
|
||||
def when(string, timezone='UTC', prefer_past=None):
|
||||
def when(string, timezone='UTC', prefer_dates_from='current_period'):
|
||||
""""Returns a MayaDT instance for the human moment specified.
|
||||
|
||||
Powered by dateparser. Useful for scraping websites.
|
||||
@@ -693,13 +693,9 @@ def when(string, timezone='UTC', prefer_past=None):
|
||||
'TIMEZONE': timezone,
|
||||
'RETURN_AS_TIMEZONE_AWARE': True,
|
||||
'TO_TIMEZONE': 'UTC',
|
||||
'PREFER_DATES_FROM': prefer_dates_from,
|
||||
}
|
||||
|
||||
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.')
|
||||
|
||||
Reference in New Issue
Block a user