python-excel/xlrd — pull request #78 by jmcnamara (2014-01-18 18:19:36+00:00)
Title: Added function to convert Excel date to datetime.

This relates to issue #76 and the initial pull request #77.

I've added a function, `xldate.xldate_as_datetime()`, to return a `datetime.datetime` object from an Excel serial date/time.

This would be useful for anyone interested in preserving milli/microseconds from an Excel date and would allow us to close Pandas issue: pydata/pandas/issues/5945.

The PR includes tests based on dates and time extracted from Excel files. The function is very slightly slower than the `xldate.xldate_as_tuple()` function:

```python
$ python
Python 2.7.2 (default, Feb 19 2013, 23:47:31)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from xlrd import xldate
>>> import timeit
>>>
>>> xldate.xldate_as_tuple(41657.75165, 0)
(2014, 1, 18, 18, 2, 23)
>>>
>>> xldate.xldate_as_datetime(41657.75165, 0)
datetime.datetime(2014, 1, 18, 18, 2, 22, 560000)
>>>
>>> timeit.timeit('xldate.xldate_as_tuple( 41657.75165, 0)', setup='from xlrd import xldate', number=170000)
1.045557975769043
>>>
>>> timeit.timeit('xldate.xldate_as_datetime(41657.75165, 0)', setup='from xlrd import xldate', number=170000)
1.0717370510101318
>>>
```
I didn't update the docs because I wasn't sure if they are auto-generated or not. If you need me to update them I can do that too.

John