Skip to content
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

Fix short weekday names #1214

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions dateparser/data/date_translation_data/en.py
Expand Up @@ -51,32 +51,39 @@
],
"monday": [
"mon",
"monday"
"monday",
"mo"
],
"tuesday": [
"tue",
"tuesday",
"tu",
"Tues"
],
"wednesday": [
"wed",
"wednesday"
"wednesday",
"we"
],
"thursday": [
"thu",
"thursday"
"thursday",
"th"
],
"friday": [
"fri",
"friday"
"friday",
"fr"
],
"saturday": [
"sat",
"saturday"
"saturday",
"sa"
],
"sunday": [
"sun",
"sunday"
"sunday",
"su"
],
"am": [
"am"
Expand Down
26 changes: 26 additions & 0 deletions dateparser/languages/locale.py
Expand Up @@ -109,6 +109,31 @@ def clean_dictionary(dictionary, threshold=2):
del dictionary[del_key]
return dictionary

@property
def weekdays(self):
weekdays = [
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday",
]
return weekdays

def remove_multiple_occurrences(self, date_str_tokens: list):
# first occurrence of day of the week will be considered
# followings occurrence(s) will be skipped and removed from the token list.
weekdays_counter = 0
for i, token in enumerate(date_str_tokens):
if token in self.weekdays:
weekdays_counter += 1

if weekdays_counter > 1:
date_str_tokens.pop(i)
continue
Comment on lines +125 to +135
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting solution. I imagine it is not perfect, but if current tests pass, onward! We can always iterate on it later.


def translate(self, date_string, keep_formatting=False, settings=None):
"""
Translate the date string to its English equivalent.
Expand Down Expand Up @@ -145,6 +170,7 @@ def translate(self, date_string, keep_formatting=False, settings=None):
if "in" in date_string_tokens:
date_string_tokens = self._clear_future_words(date_string_tokens)

self.remove_multiple_occurrences(date_string_tokens)
return self._join(
list(filter(bool, date_string_tokens)),
separator="" if keep_formatting else " ",
Expand Down
Expand Up @@ -3,9 +3,30 @@ pertain: ["of"]

sentence_splitter_group : 1

# two letters days of week

monday:
- mo

tuesday:
- tu
- Tues

wednesday:
- we

thursday:
- th

friday:
- fr

saturday:
- sa

sunday:
- su

september:
- sept

Expand Down