0

I am trying to add (shift) 6 hours to an arrow object, but somehow it seems to replace it instead:

>>> import arrow
>>> print(arrow.utcnow(),arrow.utcnow().replace(hour=+6))
2017-04-19T18:29:16.217239+00:00 2017-04-19T06:29:16.217304+00:00

The documentation gives me this example:

arw.replace(weeks=+3)

Why is it not working with hour? What am I doing wrong here?

Sebastian
  • 5,471
  • 5
  • 35
  • 53

1 Answers1

3

You need to put an s behind hour:

>>> print(arrow.utcnow(),arrow.utcnow().replace(hours=+6))
2017-04-19T18:40:41.096311+00:00 2017-04-20T00:40:41.096371+00:00

The docs are a bit hasty in their example, but you could deduce it (weeks vs week)

Or, get one with attributes shifted forward or backward:

>>> arw.replace(weeks=+3)
<Arrow [2013-06-02T03:29:35.334214+00:00]>

(from the docs)

3 and +3 parse to exactly the same (a positive value of 3), so the plus sign is not the part that makes the shift. It is only the difference between week and weeks.

In newer versions you can use .shift(hours=+6) to avoid being confused, as found in the API docs.

Sebastian
  • 5,471
  • 5
  • 35
  • 53
  • 1
    Wow, that's a really confusing interface (especially since `+6` is still just 6 - the `+` doesn't do anything - but the user's guide doesn't explain anything and makes it seem like the `+` is important). – user2357112 Apr 19 '17 at 18:44
  • 1
    According to the [API guide](http://arrow.readthedocs.io/en/latest/#arrow.arrow.Arrow.replace), the use of plural names for relative shifts is deprecated. – user2357112 Apr 19 '17 at 18:45
  • so, `replace(hours=6)` actually does not replace anything, but just adds 6 to the hours? that's super confusing. – njzk2 Apr 19 '17 at 18:45
  • 1
    @user2357112 ah that makes more sense to use `.shift(hours=+6)` unfortunately this is not yet available in my standard ubuntu package, maybe through pip though.. – Sebastian Apr 19 '17 at 18:51