arrow-py / arrow

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

incorrect tzinfo when arrow.get() #1153

Open da-head0 opened 1 year ago

da-head0 commented 1 year ago

Issue Description

when I add tzinfo as

end_time_as_cron = '1 10 4 3 *' # linux cron expression
arrow.get(end_time_as_cron, 'm H D M [*]', tzinfo='ASIA/Seoul')

the result is

end time:  0001-03-04T10:01:00+08:27:52

The timezone is not +09:00.

System Info

Thanks in advance.

krisfremen commented 1 year ago

I believe this has to do with the format you are passing, will take a deeper look, but the following works correctly:

arrow.get('2020-01-01T02:03:01', tzinfo='Asia/Seoul')
<Arrow [2020-01-01T02:03:01+09:00]>
krisfremen commented 1 year ago

That is actually some strange behavior, I will need to dig deeper to see what can be done.

andrewelkins commented 1 year ago

Odd one for sure. Add year and it'll work.

end_time_as_cron = '2020 1 10 4 3 [*]' # linux cron expression
arrow.get(end_time_as_cron, 'YYYY m H D M [*]', tzinfo='Asia/Seoul')
<Arrow [2020-03-04T10:01:00+09:00]>

edit The plot thickens. I can only reproduce with Asia/Seoul

>>> end_time_as_cron = '1 10 4 3' # linux cron expression
>>> arrow.get(end_time_as_cron, 'm H D M', tzinfo='America/Los_Angeles')
<Arrow [0001-03-04T10:01:00-08:00]>
>>> arrow.get(end_time_as_cron, 'm H D M', tzinfo='Asia/Seoul')
<Arrow [0001-03-04T10:01:00+08:27:52]>
>>> arrow.get(end_time_as_cron, 'm H D M', tzinfo='Europe/Vienna')
<Arrow [0001-03-04T10:01:00+01:00]>
>>>

Datetime.datetime has the same behavior

>>> datetime.datetime(
            1, 2, 2, 12, 30, 45, 999999, tzinfo=pytz.timezone("Asia/Seoul")
        )
datetime.datetime(1, 2, 2, 12, 30, 45, 999999, tzinfo=<DstTzInfo 'Asia/Seoul' LMT+8:28:00 STD>)
andrewelkins commented 1 year ago

Found it. It's hinted in that datetime response. LMT which explains why using a more recent year "fixes" it. https://blog.qax.io/pytz-and-strange-timezones/ https://en.wikipedia.org/wiki/Local_mean_time