arrow-py / arrow

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

Timezone in multiples of 4. #1152

Closed PeteDouma closed 1 year ago

PeteDouma commented 1 year ago

I have a modem and it returns the timezone in multiples of 4 so -16 is really -4 Arrow reads it correctly and even displays the right info

t = "23/04/24,16:29:00-16" dt = arrow.get(t,"YY/MM/DD,HH:mm:ssZZ") result is <Arrow [2023-04-24T16:29:00-16:00]>

but dt.tzinfo shows tzoffset(None, -57600)

I need to change the tz to -4, but how do I access the ZZ info?

krisfremen commented 1 year ago
t = "23/04/24,16:29:00-16"
dt = arrow.get(t,"YY/MM/DD,HH:mm:ssZZ")
2023-04-24T16:29:00-16:00
dt.replace(tzinfo=tzoffset(None, dt.tzinfo._offset.total_seconds()/4))
2023-04-24T16:29:00-04:00

@PeteDouma One way of doing it, but I would suggest parsing and modiying the timezone before it is passed to arrow, since technically, we don't validate the timezones against the tz db instead just the timedelta limit of +/- 24 hours is enforced and you might go above that if the timezone is 6+.