On 2016-01-15 13:44, Tomas Babej wrote: > Hi, > > For the dates older than 1900, Python is unable to convert the datetime > representation to string using strftime: > > https://bugs.python.org/issue1777412 > > Work around the issue adding a custom method to convert the datetime > objects to LDAP generalized time strings. > > https://fedorahosted.org/freeipa/ticket/5579
I noticed that all previous strftime() calls and the new code ignore any time zone information. This isn't an issue for tz-naive datetime object that don't have any time zone information attached. You can't fix them anyway and just hope they are always UTC. For tz-aware datetime object your approach returns the wrong value. You can use datetime.utctimetuple() instead. The method returns a time tuple in UTC. >>> value datetime.datetime(2016, 1, 18, 8, 2, 49, 646270) >>> '{0.tm_year:4d}{0.tm_mon:02d}{0.tm_mday:02d}{0.tm_hour:02d}{0.tm_min:02d}{0.tm_sec:02d}Z'.format(value.utctimetuple()) '20160118080249Z' https://docs.python.org/2/library/datetime.html#datetime.datetime.utctimetuple
signature.asc
Description: OpenPGP digital signature
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code