2

I am using from dateutil import parser to parse an input but for some reason it is giving me back the wrong timezone.

My code: parser.parse(input_date)

Input: Tue May 01 2018 13:23:00 GMT+0200 (CEST)

Output: 2018-05-01 13:23:00-02:00

Does anybody know why the parse method changes the +2 timezone to -2?

kemis
  • 4,404
  • 6
  • 27
  • 40

2 Answers2

1

That is being interpreted as a POSIX style offset, which is specified in a way that is inverted from what you expect. See the documentation on tzstr.

You can see that dealing with this is open issue #70 on the tracker.

For now, your best options depend on what your data looks like. If you are generating the strings yourself, changing them to a different format is the easiest choice. If you are parsing arbitrary strings, writing a custom tzinfos function or manually detecting this situation and correcting it after the fact may be your best option.

Paul
  • 10,381
  • 13
  • 48
  • 86
0

Because the issue is open on github as Paul said I had to make a custom solution. I parsed the input using re and changed it from: Tue May 01 2018 13:23:00 GMT+0200 (CEST) to Tue May 01 2018 13:23:00 +0200, dateutil.parser.parse had no problem parsing this format.

kemis
  • 4,404
  • 6
  • 27
  • 40