Patch review: [ 1100942 ] datetime.strptime constructor added

I see a need for this patch - I've had to write "datetime(*(time.strptime(date_string, format)[0:6]))" far too many times. I don't understand the C API well enough to check if reference counts are handled properly, but otherwise the implementation looks straight forward. Documentation looks good and the test passes on my machine. Two suggestions: 1. In the time module, the strptime() function's format parameter is optional. For consistency's sake, I'd expect datetime.strptime()'s format parameter also to be optional. (On the other hand, the default value for the format is not very useful.) 2. Since strftime is supported by datetime.time, datetime.date and datetime.datetime, I'd also expect strptime to be supported by all three classes. Could you add that now, or would it be better to do it as a separate patch? Alan. -- Alan Green alan.green@cardboard.nu - http://cardboard.nu

Alan> 1. In the time module, the strptime() function's format Alan> parameter is optional. For consistency's sake, I'd expect Alan> datetime.strptime()'s format parameter also to be optional. (On Alan> the other hand, the default value for the format is not very Alan> useful.) Correct. No need to propagate a mistake. Alan> 2. Since strftime is supported by datetime.time, Alan> datetime.date and datetime.datetime, I'd also expect strptime to Alan> be supported by all three classes. Could you add that now, or Alan> would it be better to do it as a separate patch? That can probably be done, but I'm not convinced strftime really belongs on either date or time objects given the information those objects are missing: >>> t = datetime.datetime.now().time() >>> t.strftime("%Y-%m-%d") '1900-01-01' >>> d = datetime.datetime.now().date() >>> d.strftime("%H:%M:%S") '00:00:00' I would be happy for strftime to only be available for datetime objects (assuming there was a good way to get from time or date objects to datetime objects short of extracting their individual attributes). In any case, going from datetime to date or time objects is trivial: >>> dt = datetime.datetime.now() >>> dt.time() datetime.time(21, 12, 18, 705365) so parsing a string into a datetime object then splitting out date and time objects seems reasonable. Skip
participants (2)
-
Alan Green
-
Skip Montanaro