> From: Matthew Hughes > To: generateds-users@lists.sourceforge.net > Sent: Tuesday, January 29, 2013 9:52 AM
> > Hi - I recently upgraded to the new 2.8a version, and ran into a minor > issue with the dateTime parsing code. > > In particular, I'm receiving messages with times including fractional > seconds, i.e. "2013-01-29T00:53:58.545024". I'm no XML expert, but a > quick web search seems to indicate that this is a valid xsd:dateTime > instance - i.e. http://books.xmlschemata.org/relaxng/ch19-77049.html > includes in the valid example list "2001-10-26T21:32:52.12679". > > This results in an exception: > .... in gds_parse_datetime > '%Y-%m-%dT%H:%M:%S').replace(tzinfo = tz) > File "/usr/lib64/python2.6/_strptime.py", line 328, in _strptime > data_string[found.end():]) > ValueError: unconverted data remains: .545024 > > There may be a more elegant solution, but I tweaked my generated code by > modifying gds_parse_datetime() like: > > - return datetime.strptime(input_data, > - '%Y-%m-%dT%H:%M:%S').replace(tzinfo = tz) > + if len(input_data.split('.')) > 1: > + dt = datetime.strptime(input_data, '%Y-%m-%dT%H:%M:%S.%f') > + else: > + dt = datetime.strptime(input_data, '%Y-%m-%dT%H:%M:%S') > + return dt.replace(tzinfo = tz) Matt - This seems like a good fix to me. I've added it to the current code. And, I've added analogous code to gds_format_datetime so that the fractional seconds are preserved during export. I'll send you a patched version in a separate email. The new code is also available in a Mercurial repository at https://bitbucket.org/dkuhlman/generateds Thanks much for fixing this. - Dave > > This seems to produce correct results with and without the fractional > second - though note per > http://stackoverflow.com/questions/698223/how-can-i-parse-a-time-string-containing-milliseconds-in-it-with-python > the %f conversion type is new in python 2.6 - not a problem for me but > I don't know how backwards compatible you want to be ... Python-2.6 seems to go back far enough. If someone has an issue with this and their schema uses dateTime and the XML instance doc has fractional seconds, then we/they can always patch it. > > Thanks for the time maintaining the tool! You're welcome. - Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_jan _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users