Increment date with arrow in python not changing properties

140 views Asked by At

I am using .replace and .shift method to increment/decrement an arrow date. However the behaviour is completely unexpected. See the python session below as example.

>>> import arrow
>>> ref = arrow.get('2019-08-01', 'YYYY-MM-DD')
>>> ref.weekday()
3
>>> ref.day
1
>>> ref.shift(days=1)
<Arrow [2019-08-02T00:00:00+00:00]>
>>> ref.weekday()
3
>>> ref.day
1
>>> ref
<Arrow [2019-08-01T00:00:00+00:00]>
>>> 

After I shifted the arrow by one day I would expect weekday and day properties to be incremented. However they stay the same. Any explanation to this?

Using replace does the same thing.

1

There are 1 answers

2
X3R0 On BEST ANSWER

Try this: ref = ref.shift(days=1)

shift doesn't update the object, it returns an updated object...

C:\Users\deanv>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> ref = arrow.get('2019-08-01', 'YYYY-MM-DD')
>>> ref.weekday()
3
>>> ref.day
1
>>> ref = ref.shift(days=1)
>>> ref.weekday()
4
>>> ref.day
2
>>>