Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
.vscode/

# C extensions
*.so
Expand Down
16 changes: 8 additions & 8 deletions flask_ask/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@

_DATE_PATTERNS = {
# "today", "tomorrow", "november twenty-fifth": 2015-11-25
'^\d{4}-\d{2}-\d{2}$': '%Y-%m-%d',
r"^\d{4}-\d{2}-\d{2}$": "%Y-%m-%d",
# "this week", "next week": 2015-W48
'^\d{4}-W\d{2}$': '%Y-W%U-%w',
r"^\d{4}-W\d{2}$": "%Y-W%U-%w",
# "this weekend": 2015-W48-WE
'^\d{4}-W\d{2}-WE$': '%Y-W%U-WE-%w',
r"^\d{4}-W\d{2}-WE$": "%Y-W%U-WE-%w",
# "this month": 2015-11
'^\d{4}-\d{2}$': '%Y-%m',
r"^\d{4}-\d{2}$": "%Y-%m",
# "next year": 2016
'^\d{4}$': '%Y',
r"^\d{4}$": "%Y",
}


def to_date(amazon_date):
# make so 'next decade' matches work against 'next year' regex
amazon_date = re.sub('X$', '0', amazon_date)
amazon_date = re.sub("X$", "0", amazon_date)
for re_pattern, format_pattern in list(_DATE_PATTERNS.items()):
if re.match(re_pattern, amazon_date):
if '%U' in format_pattern:
if "%U" in format_pattern:
# http://stackoverflow.com/a/17087427/1163855
amazon_date += '-0'
amazon_date += "-0"
return datetime.strptime(amazon_date, format_pattern).date()
return None

Expand Down
Loading