Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Support for dates without time #3
In workbook.py, there is currently only support for the full datetime type. It would be beneficial to include support for datetime.time and datetime.date as well.
A simple implementation would be:
if isinstance(date, datetime.date): # separate handling for partial date # date in excel is number of days since Jan1 1900 d = datetime.datetime.fromordinal( date.toordinal() ) - datetime.datetime( 1900, 1, 1 ) number = d.days elif isinstance(date, datetime.time): # separate handling for partial time # time in excel is float between 0 and 1. Use time in seconds from 00:00, divided by seconds in a day number = (date.hour_60_60.0 + date.minute_60.0 + date.second + 1.0_date.microsecond/1e6)/(24_60_60.0) else: # existing version for full datetime number = self._convert_date_time(date)
Thanks Josh. I was going to suggest something like that as a workaround.
My general philosophy in the past has been to not modify the API for issues that can be solved in the user's space since that requires more testing and documentation on my side. This in turn takes time from adding features that can't be implemented by the user.
However, in cases where I've seen repeated workarounds from users I have modified the API. For example I resisted adding a
So I'll leave the API as it is for now. If this becomes an issue I will respond to it.
And thanks for the prompt reply.
I am also late with this, but I just checked the new build.
Thanks a lot!
The only thing I would still wish for here would be if there would be a default format for time-only and date-only, so that one can pass values without making type-dependent handling.
Do you mean that it would be nice to have a default cell format, so you don't have to add things like this:
I'm going to assume that is what you mean and answer that question.
There are a couple of reasons that isn't there:
I have considered this in the past and also providing some
In the end it hasn't been a big issue with most users but I am open to adding a change like this. So, I'll keep it in mind.
If you want you can open an new issue and I'll mark it as a feature request so that it isn't forgotten.