-
Notifications
You must be signed in to change notification settings - Fork 26
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
🌵 Show search error if input is not a date #2453
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2453 +/- ##
======================================
Coverage 100% 100%
======================================
Files 225 225
Lines 25426 25434 +8
======================================
+ Hits 25426 25434 +8
Continue to review full report at Codecov.
|
@@ -11,13 +11,12 @@ | |||
MAX_UTC_OFFSET = 14 * 60 * 60 | |||
|
|||
# pattern for any date which should be parsed by the ISO8601 library (assumed to be not human-entered) | |||
FULL_ISO8601_REGEX = regex.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.(\d{,9}))?([\+\-]\d{2}:\d{2}|Z)$") | |||
FULL_ISO8601_REGEX = regex.compile(r"^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\.(\d{,9}))?([\+\-]\d{2}:\d{2}|Z)$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added <space>
as a delimiter between date and time
DD_MM_YYYY = regex.compile(r"\b([0-9]{1,2})[-.\\/_ ]([0-9]{1,2})[-.\\/_ ]([0-9]{4}|[0-9]{2})\b") | ||
MM_DD_YYYY = regex.compile(r"\b([0-9]{1,2})[-.\\/_ ]([0-9]{1,2})[-.\\/_ ]([0-9]{4}|[0-9]{2})\b") | ||
YYYY_MM_DD = regex.compile(r"\b([0-9]{4}|[0-9]{2})[-.\\/_ ]([0-9]{1,2})[-.\\/_ ]([0-9]{1,2})\b") | ||
DD_MM_YYYY = regex.compile(r"\b([0-9]{1,2})[-.\\/_]([0-9]{1,2})[-.\\/_]([0-9]{4}|[0-9]{2})\b") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed <space>
as a delimiter, i've only seen spaces used when date has full/abbr month like: 20th June, 2019
or 13. Dec 2019
, we don't support those
# maybe it is similar to iso date ? | ||
if not parsed: | ||
if dayfirst: | ||
parsed = _date_from_formats(date_str, YYYY_MM_DD, 3, 2, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YYYY_MM_DD
is similar to ISO date, it supports single digit month/day but requires a 4 digit year, and works with multiple delimiters
this format was probably used in the past, but support was perhaps dropped because it was clashing with ISO_YYYY_MM_DD
I've checked dynamic groups on both, RP and TX, that use a contactfield (value_type='D') for any weird date input strings, and there are no weird looking inputs. there is about 35 contactgroups in total here is the SQL i've used to check the contactgroups:
|
@@ -41,6 +40,37 @@ def datetime_to_str(date_obj, format, tz): | |||
return date_obj.strftime(format) | |||
|
|||
|
|||
def str_to_date(date_str, dayfirst=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good, how about a verbose comment for this method that describes in prose what dates we accept and what our logic is there? Just to document for future us what we mean to support.
No description provided.