From 6bbdac35eceb70e2f7a489913b2a24ae2d822b3e Mon Sep 17 00:00:00 2001 From: Gourav Kumar Date: Fri, 11 Mar 2022 09:42:22 +0530 Subject: [PATCH] parse_dates decorator works with optional date params --- fincal/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fincal/core.py b/fincal/core.py index 8f04abf..5ea8893 100644 --- a/fincal/core.py +++ b/fincal/core.py @@ -37,6 +37,7 @@ def date_parser(*pos): Each of the dates is automatically parsed into a datetime.datetime object from string. """ + def parse_dates(func): def wrapper_func(*args, **kwargs): date_format = kwargs.get("date_format", None) @@ -49,9 +50,15 @@ def date_parser(*pos): date = kwargs.get(kwarg, None) in_args = False if date is None: - date = args[j] + try: + date = args[j] + except IndexError: + pass in_args = True + if date is None: + continue + parsed_date = _parse_date(date, date_format) if not in_args: kwargs[kwarg] = parsed_date