Python date parsing results

I use the dateutil library to parse date strings and get weird results. I assumed that the following date lines would be equal, and the abbreviation in the time zone in brackets is actually optional, but when casting, I get a completely different value:

import datetime   
import dateutil.parser

parsed_d1 = dateutil.parser.parse('Sun May 13 2012 00:00:00 GMT-0400 (EDT)')   
parsed_d2 = dateutil.parser.parse('Sun May 13 2012 00:00:00 GMT-0400')   
parsed_d3 = dateutil.parser.parse('Sun May 13 2012 00:00:00-0400')   

print str(parsed_d1)   
print str(parsed_d2)   
print str(parsed_d3) 

Conclusion:

2012-05-13 00:00:00-04:00   
2012-05-13 00:00:00+04:00   
2012-05-13 00:00:00-04:00  

Can someone explain what is going on here?

+3
source share
1 answer

EDT , . . . 4 EDT, GMT. ( ) . : "EDT +4 GMT".

http://bazaar.launchpad.net/~dateutil/dateutil/trunk/view/head:/dateutil/parser.py , , , GMT-0400,

# Check for something like GMT+3, or BRST+3. Notice
# that it doesn't mean "I am 3 hours after GMT", but
# "my time +3 is GMT". If found, we reverse the
# logic so that timezone parsing code will get it
# right.

, GMT-0400 " -4 GMT". , .

, , - (EDT), . , , , -0400 , .

( , ) GMT-0400 , , . .

, ; , .

, , , , . , , ( ). , python, - , (, , ).

UPDATE , simple-date . , , - , , pytz .

+3

All Articles