Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dateutil.parser.parse() giving different results for BST in Linux and Windows #1357

Open
HughMacdonald opened this issue Mar 31, 2024 · 1 comment

Comments

@HughMacdonald
Copy link

I'm seeing some odd behaviour here between the Linux (on a Raspberry Pi) and Windows.

Firstly, dateutil._version.version gives me 2.9.0.post0 on both systems. Linux is running Python 3.11.2 and Windows is running Python 3.10.11.

I am in the UK, so local timezone is (as of this morning) BST, which is UTC+01:00. Both of the machines I'm running this on a

Here's my test code:

from dateutil import parser
t_str = '2024-03-31 02:00:25 BST+0100'
t = parser.parse(t_str)
print(t.tzinfo())
# Linux : tzlocal()
# Windows : tzoffset('BST', -3600)
print(t.timestamp())
# Linux : 1711846825.0
# Windows : 1711854025.0

So it appears that something on Windows is treating the BST+0100 as an hour offset the other way. (If I change the string to be BST-0100 it does it to +3600)

The string I'm getting here is coming from an external source, so I can't change the format of it.

If I import tzlocal and run tzlocal.get_localzone() on both machines, I get Europe/London on both

Any idea why this is happening? Am I doing something wrong, or is this a bug in the parser somewhere along the way?

@HughMacdonald
Copy link
Author

I found that passing in tzinfos={"GMT": 0, "BST": 3600} fixed my issue. Without this, though, I'm not sure why it wasn't just ignoring the BST/GMT in the string and using the +0100 as the offset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant