Sebastian
Sebastian

Reputation: 5999

python arrow shifting hours

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?

Upvotes: 0

Views: 4431

Answers (1)

Sebastian
Sebastian

Reputation: 5999

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.

Upvotes: 4

Related Questions