New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect date when using .when with weekdays #146
Comments
Hi! Thanks for contribution!
Great! 🎉 @kennethreitz what about exposing the Something like: maya.when('monday', prefer_dates_from='past') |
@timofurrer I had thought: -def when(string, timezone='UTC', prefer_past=False):
+def when(string, timezone='UTC', prefer_past=None):
- 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) This should allow all three of dateparsers options of 'current_period', 'future', and 'past' and not break anything else. |
Sounds even better! |
I might have second thoughts about the proposed API. Having both arguments |
I agree. My thoughts behind keeping I think because -def when(string, timezone='UTC', prefer_past=False):
+def when(string, timezone='UTC', prefer_dates_from='current_period'):
settings = {
'TIMEZONE': timezone,
'RETURN_AS_TIMEZONE_AWARE': True,
'TO_TIMEZONE': 'UTC',
+ 'PREFER_DATES_FROM': prefer_dates_from,
}
- if prefer_past:
- settings['PREFER_DATES_FROM'] = 'past'
+
dt = dateparser.parse(string, settings=settings)
if dt is None:
raise ValueError('invalid datetime input specified.') Let me know and I can push up some changes ✨ |
Yes, let's do that! @kennethreitz any thoughts on that one? |
Done in #147 |
hello! 👋
There appears to be an issue with
maya.when()
when using weekday names.dateparser seems to handle this correctly, but only when the setting 'PREFER_DATES_FROM' is set to 'future'.
The default setting for dateparser appears to be
"current_period"
from dateparser/dateparser_data/settings.py.As the only way to alter the 'PREFER_DATES_FROM' setting is change
prefer_past
, there is currently no way to get the future day in this instance.I'll open a PR with a failing test.
The text was updated successfully, but these errors were encountered: