diff --git a/CHANGELOG.md b/CHANGELOG.md index 9430dc07..5e4f84e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Improve Arrow 0.15.0 support after changes in `arrow.get()` behavior (#296) + ### Fixed - Stylize prompt to create new project or tag (#310). diff --git a/watson/cli.py b/watson/cli.py index 26f8f41d..47b3c9c7 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -75,7 +75,7 @@ def convert(self, value, param, ctx): if value: try: date = arrow.get(value) - except arrow.parser.ParserError as e: + except (ValueError, TypeError) as e: raise click.UsageError(str(e)) # When we parse a date, we want to parse it in the timezone # expected by the user, so that midnight is midnight in the local @@ -630,7 +630,7 @@ def _final_print(lines): if aggregated: _print(u'{} - {}'.format( style('date', '{:ddd DD MMMM YYYY}'.format( - arrow.get(report['timespan']['from']) + report['timespan']['from'] )), style('time', '{}'.format(format_timedelta( datetime.timedelta(seconds=report['time']) @@ -640,10 +640,10 @@ def _final_print(lines): else: _print(u'{} -> {}\n'.format( style('date', '{:ddd DD MMMM YYYY}'.format( - arrow.get(report['timespan']['from']) + report['timespan']['from'] )), style('date', '{:ddd DD MMMM YYYY}'.format( - arrow.get(report['timespan']['to']) + report['timespan']['to'] )) )) @@ -1244,7 +1244,7 @@ def edit(watson, confirm_new_project, confirm_new_tag, id): # break out of while loop and continue execution of # the edit function normally break - except (ValueError, RuntimeError) as e: + except (ValueError, TypeError, RuntimeError) as e: click.echo(u"Error while parsing inputted values: {}".format(e), err=True) except KeyError: diff --git a/watson/frames.py b/watson/frames.py index 45026941..b70b2cac 100644 --- a/watson/frames.py +++ b/watson/frames.py @@ -15,18 +15,18 @@ def __new__(cls, start, stop, project, id, tags=None, updated_at=None,): if not isinstance(stop, arrow.Arrow): stop = arrow.get(stop) - except RuntimeError as e: + + if updated_at is None: + updated_at = arrow.utcnow() + elif not isinstance(updated_at, arrow.Arrow): + updated_at = arrow.get(updated_at) + except (ValueError, TypeError) as e: from .watson import WatsonError raise WatsonError(u"Error converting date: {}".format(e)) start = start.to('local') stop = stop.to('local') - if updated_at is None: - updated_at = arrow.utcnow() - elif not isinstance(updated_at, arrow.Arrow): - updated_at = arrow.get(updated_at) - if tags is None: tags = [] diff --git a/watson/utils.py b/watson/utils.py index 5c218044..82a50d66 100644 --- a/watson/utils.py +++ b/watson/utils.py @@ -378,12 +378,8 @@ def flatten_report_for_csv(report): of the report. """ result = [] - datetime_from = arrow.get( - report['timespan']['from'] - ).format('YYYY-MM-DD HH:mm:ss') - datetime_to = arrow.get( - report['timespan']['to'] - ).format('YYYY-MM-DD HH:mm:ss') + datetime_from = report['timespan']['from'].format('YYYY-MM-DD HH:mm:ss') + datetime_to = report['timespan']['to'].format('YYYY-MM-DD HH:mm:ss') for project in report['projects']: result.append({ 'from': datetime_from, diff --git a/watson/watson.py b/watson/watson.py index 60e88594..62dc2c1f 100644 --- a/watson/watson.py +++ b/watson/watson.py @@ -99,9 +99,11 @@ def _load_json_file(self, filename, type=dict): ) def _parse_date(self, date): + """Returns Arrow object from timestamp.""" return arrow.Arrow.utcfromtimestamp(date).to('local') def _format_date(self, date): + """Returns timestamp from string timestamp or Arrow object.""" if not isinstance(date, arrow.Arrow): date = arrow.get(date) @@ -494,8 +496,8 @@ def report(self, from_, to, current=None, projects=None, tags=None, report = { 'timespan': { - 'from': str(span.start), - 'to': str(span.stop), + 'from': span.start, + 'to': span.stop, }, 'projects': [] }