Skip to content

Commit

Permalink
Fix fatal AttributeError using Arrow 0.14.5
Browse files Browse the repository at this point in the history
Since Arrow 0.14.5, Arrow.replace() has dropped shift functionality
in favor of Arrow.shift(). This causes an AttributeError exception
every time watson is run.

The error message is: 'AttributeError: unknown attribute: "days"'
  • Loading branch information
davidag committed Aug 16, 2019
1 parent 699ccda commit d30dfef
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Update zsh shell completion (#264).
- Fix fatal AttributeError using Arrow 0.14.5 (#300)

### Removed

Expand Down
11 changes: 5 additions & 6 deletions scripts/fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@

now = arrow.now()

for date in arrow.Arrow.range('day', now.replace(months=-1), now):
for date in arrow.Arrow.range('day', now.shift(months=-1), now):
if date.weekday() in (5, 6):
# Weekend \o/
continue

start = date.replace(
hour=9, minute=random.randint(0, 59), seconds=random.randint(0, 59)
)
start = date.replace(hour=9, minute=random.randint(0, 59)) \
.shift(seconds=random.randint(0, 59))

while start.hour < random.randint(16, 19):
project, tags = random.choice(projects)
frame = watson.frames.add(
project,
start,
start.replace(seconds=random.randint(60, 4 * 60 * 60)),
start.shift(seconds=random.randint(60, 4 * 60 * 60)),
tags=random.sample(tags, random.randint(0, len(tags)))
)
start = frame.stop.replace(seconds=random.randint(0, 1 * 60 * 60))
start = frame.stop.shift(seconds=random.randint(0, 1 * 60 * 60))

watson.save()
6 changes: 3 additions & 3 deletions watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def status(watson, project, tags, elapsed):
@click.option('-c/-C', '--current/--no-current', 'current', default=None,
help="(Don't) include currently running frame in report.")
@click.option('-f', '--from', 'from_', cls=MutuallyExclusiveOption, type=Date,
default=arrow.now().replace(days=-7),
default=arrow.now().shift(days=-7),
mutually_exclusive=_SHORTCUT_OPTIONS,
help="The date from when the report should start. Defaults "
"to seven days ago.")
Expand Down Expand Up @@ -694,7 +694,7 @@ def _final_print(lines):
@click.option('-c/-C', '--current/--no-current', 'current', default=None,
help="(Don't) include currently running frame in report.")
@click.option('-f', '--from', 'from_', cls=MutuallyExclusiveOption, type=Date,
default=arrow.now().replace(days=-7),
default=arrow.now().shift(days=-7),
mutually_exclusive=_SHORTCUT_OPTIONS,
help="The date from when the report should start. Defaults "
"to seven days ago.")
Expand Down Expand Up @@ -835,7 +835,7 @@ def aggregate(ctx, watson, current, from_, to, projects, tags, output_format,
@click.option('-c/-C', '--current/--no-current', 'current', default=None,
help="(Don't) include currently running frame in output.")
@click.option('-f', '--from', 'from_', type=Date,
default=arrow.now().replace(days=-7),
default=arrow.now().shift(days=-7),
help="The date from when the log should start. Defaults "
"to seven days ago.")
@click.option('-t', '--to', type=Date, default=arrow.now(),
Expand Down
4 changes: 2 additions & 2 deletions watson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_start_time_for_period(period):
if period == 'day':
start_time = arrow.Arrow(year, month, day)
elif period == 'week':
start_time = arrow.Arrow.fromdate(now.replace(days=-weekday).date())
start_time = arrow.Arrow.fromdate(now.shift(days=-weekday).date())
elif period == 'month':
start_time = arrow.Arrow(year, month, 1)
elif period == 'luna':
Expand Down Expand Up @@ -204,7 +204,7 @@ def apply_weekday_offset(start_time, week_start):
return start_time
now = datetime.datetime.now()
offset = weekdays[new_start] - 7 * (weekdays[new_start] > now.weekday())
return start_time.replace(days=offset)
return start_time.shift(days=offset)


def make_json_writer(func, *args, **kwargs):
Expand Down

0 comments on commit d30dfef

Please sign in to comment.