Skip to content

Commit

Permalink
Hotfix id sunday (#1134)
Browse files Browse the repository at this point in the history
* Add new rule for 'week' and remove existing 'week' translation from Indonesia (id)

* Update id

* Simplify extension of “week ago” support for Indonesian

* Indonesian: interpret minggu as Sunday if not following a number

---------

Co-authored-by: Adrián Chaves <[email protected]>
  • Loading branch information
serhii73 and Gallaecio committed Jan 31, 2023
1 parent bedc881 commit 350cafa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
9 changes: 8 additions & 1 deletion dateparser/data/date_translation_data/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@
],
"\\1 week ago": [
"(\\d+[.,]?\\d*) mgg lalu",
"(\\d+[.,]?\\d*) minggu yang lalu"
"(\\d+[.,]?\\d*) minggu yang lalu",
"(\\d+[.,]?\\d*) minggu lalu"
],
"\\1 year ago": [
"(\\d+[.,]?\\d*) tahun yang lalu",
Expand Down Expand Up @@ -235,6 +236,12 @@
"in \\1 year": [
"dalam (\\d+[.,]?\\d*) tahun",
"dlm (\\d+[.,]?\\d*) thn"
],
"\\1 week": [
"(\\d+[.,]?\\d*) minggu"
],
"sunday": [
"minggu"
]
},
"locale_specific": {},
Expand Down
1 change: 1 addition & 0 deletions dateparser/languages/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def translate(self, date_string, keep_formatting=False, settings=None):
for pattern, replacement in relative_translations.items():
if pattern.match(word):
date_string_tokens[i] = pattern.sub(replacement, word)
break
else:
if word in dictionary:
fallback = word if keep_formatting and not word.isalpha() else ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ relative-type:
- baru saja

relative-type-regex:
\1 week ago:
- (\d+[.,]?\d*) minggu lalu
\1 month ago:
- (\d+[.,]?\d*) bulan lalu

\1 year ago:
- (\d+[.,]?\d*) tahun lalu
\1 week:
- (\d+[.,]?\d*) minggu
sunday:
- minggu
5 changes: 1 addition & 4 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ def is_invalid_relative_regex_mapping(relative_regex_mapping):
key, value = relative_regex_mapping
if not (key and value and isinstance(key, str) and isinstance(value, list)):
return True
if '\\1' not in key:
return True
return not (all([isinstance(x, str) for x in value])
and all(['(\\d+[.,]?\\d*)' in x for x in value]))
return not all([isinstance(x, str) for x in value])


class TestLocaleInfo(BaseTestCase):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ def setUp(self):
# Tagalog
param('tl', "Biyernes Hulyo 3, 2015", "friday july 3 2015"),
param('tl', "Pebrero 5, 2015 7:00 pm", "february 5 2015 7:00 pm"),
# Indonesian
param('id', "06 Sep 2015", "06 september 2015"),
param('id', "07 Feb 2015 20:15", "07 february 2015 20:15"),
param('id', "Minggu, 18 Mar 2018 07:30", "sunday 18 march 2018 07:30"),
param('id', "3 minggu yang lalu", "3 week ago"),
param('id', "5 minggu", "5 week"),
# Miscellaneous
param('en', "2014-12-12T12:33:39-08:00", "2014-12-12 12:33:39-08:00"),
Expand Down

0 comments on commit 350cafa

Please sign in to comment.