[Freeipa-devel] [PATCH 0397] ipapython: Use custom datetime to LDAP generalized time

Petr Spacek pspacek at redhat.com
Tue Jan 19 10:26:41 UTC 2016


On 18.1.2016 08:06, Christian Heimes wrote:
> 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

Dates before 1900? Seriously? This is a bad idea.

I would rather catch ValueError and inform the user. We seriously do not need
more custom code!

Petr^2 Spacek

> 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




More information about the Freeipa-devel mailing list