arrow-py / arrow

🏹 Better dates & times for Python
https://arrow.readthedocs.io
Apache License 2.0
8.71k stars 673 forks source link

Allow fold kwarg in arrow.get() #872

Open systemcatch opened 3 years ago

systemcatch commented 3 years ago

Currently there is no way to specify which side of an ambiguous datetime we want when creating with arrow.get(). It'd be nice to be able to do the following.

arrow.get("2001-10-28 01:00:00", "YYYY-MM-DD HH:mm:ss", tzinfo="US/Pacific", fold=1)
yiransii commented 3 years ago

Hello, I am interested in implementing this. After reading the arrow.get() API, I still find the description ambiguous. Can you elaborate on "which side of an ambiguous datetime"? Are both tzinfo="US/Pacific", fold=1 new features and what does fold=1 mean? thanks. @systemcatch

yiransii commented 3 years ago

@systemcatch Hello I saw this stackoverflow post regarding fold. Fold is related to ambiguous local time due to reasons like local time change. Is this what you mean by fold? https://stackoverflow.com/questions/43359227/python-3-6-local-time-disambiguation-pep-495

systemcatch commented 3 years ago

Hi @yiransii that is exactly what I meant by fold.

yiransii commented 3 years ago

@systemcatch Hello Chris,

I traced back to the get() method, and it points to the arrow constructor when there are more than 3 args. https://github.com/arrow-py/arrow/blob/1278a21b46fcf145592f15b47a8169f97f54415a/arrow/factory.py#L250

I am wondering if we are still updating the enfold method in the arrow constructor? https://github.com/arrow-py/arrow/blob/1278a21b46fcf145592f15b47a8169f97f54415a/arrow/arrow.py#L93

Thanks!

systemcatch commented 3 years ago

Hey @yiransii for now we can stick with the enfold method. We just need to make sure that the fold kwarg is handled correctly in the get() method (https://github.com/arrow-py/arrow/blob/master/arrow/factory.py#L146).

sania-dsouza commented 2 years ago

hey @systemcatch, What output are we expecting for your example command: arrow.get("2001-10-28 01:00:00", "YYYY-MM-DD HH:mm:ss", tzinfo="US/Pacific", fold=1)

systemcatch commented 2 years ago

@sania-dsouza we would expect the following.

>>> arrow.Arrow(2001, 10, 28, 1, tzinfo="US/Pacific")
<Arrow [2001-10-28T01:00:00-07:00]>
>>> arrow.Arrow(2001, 10, 28, 1, tzinfo="US/Pacific", fold=1)
<Arrow [2001-10-28T01:00:00-08:00]>
nik-k11 commented 1 year ago

Hello @systemcatch I've opened a pull request for the feature.

BTW, this notation was already working, since all the arguments would be passed into Arrow constructor 🙃

@sania-dsouza we would expect the following.

>>> arrow.Arrow(2001, 10, 28, 1, tzinfo="US/Pacific")
<Arrow [2001-10-28T01:00:00-07:00]>
>>> arrow.Arrow(2001, 10, 28, 1, tzinfo="US/Pacific", fold=1)
<Arrow [2001-10-28T01:00:00-08:00]>