Skip to content

Commit

Permalink
Parse short versions of day, month, and year (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii73 committed Nov 24, 2022
1 parent a51d9bd commit 89a5b29
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dateparser/data/date_translation_data/en.py
Expand Up @@ -87,11 +87,13 @@
"year": [
"year",
"yr",
"y",
"years"
],
"month": [
"mo",
"month",
"mon",
"months"
],
"week": [
Expand All @@ -101,6 +103,7 @@
],
"day": [
"day",
"d",
"days"
],
"hour": [
Expand Down
Expand Up @@ -13,12 +13,15 @@ decade:
- decade
- decades
year:
- y
- years
month:
- mon
- months
week:
- weeks
day:
- d
- days
hour:
- h
Expand Down
3 changes: 3 additions & 0 deletions tests/test_freshness_date_parser.py
Expand Up @@ -72,6 +72,7 @@ def test_relative_past_dates_with_time_as_period(self, date_string, ago, period)
param('an hour ago', ago={'hours': 1}, period='day'),
param('about an hour ago', ago={'hours': 1}, period='day'),
param('a day ago', ago={'days': 1}, period='day'),
param('1d ago', ago={'days': 1}, period='day'),
param('a week ago', ago={'weeks': 1}, period='week'),
param('2 hours ago', ago={'hours': 2}, period='day'),
param('about 23 hours ago', ago={'hours': 23}, period='day'),
Expand All @@ -96,8 +97,10 @@ def test_relative_past_dates_with_time_as_period(self, date_string, ago, period)
param('nine hours ago', ago={'hours': 9}, period='day'),
param('three week ago', ago={'weeks': 3}, period='week'),
param('eight months ago', ago={'months': 8}, period='month'),
param('1mon ago', ago={'months': 1}, period='month'),
param('six days ago', ago={'days': 6}, period='day'),
param('five years ago', ago={'years': 5}, period='year'),
param('2y ago', ago={'years': 2}, period='year'),
# Fractional units
param('2.5 hours', ago={'hours': 2.5}, period='day'),
param('10.75 minutes', ago={'minutes': 10.75}, period='day'),
Expand Down

0 comments on commit 89a5b29

Please sign in to comment.