diff options
author | Wolfgang Müller | 2021-04-27 17:41:14 +0200 |
---|---|---|
committer | Wolfgang Müller | 2021-04-28 20:15:53 +0200 |
commit | 5213365b42640d5f5dcba5adde071100d49fe2b0 (patch) | |
tree | c6df9f2e939fdaae8bce209a02c076f18cf846e3 /quarg/utils.py | |
parent | f994851c472d097a4cd34da42abc16bea30dc4c6 (diff) | |
download | quarg-5213365b42640d5f5dcba5adde071100d49fe2b0.tar.gz |
Split errx and parse_isodate out into utils.py
We're going to need this for an upcoming commit that moves all
argparse.Action classes to its own file.
Diffstat (limited to '')
-rw-r--r-- | quarg/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/quarg/utils.py b/quarg/utils.py new file mode 100644 index 0000000..7fa270e --- /dev/null +++ b/quarg/utils.py @@ -0,0 +1,15 @@ +import sys +import dateutil.parser + +def errx(msg): + sys.exit(f'quarg: {msg}') + +def parse_isodate(date): + try: + parsed = dateutil.parser.isoparse(date) + except ValueError as err: + errx(f'isoparse: invalid date format \'{date}\', {err}') + except OverflowError as err: + errx(f'isoparse: date overflows: \'{date}\'') + + return parsed |