[Patches] [ python-Patches-1100942 ] datetime.strptime constructor added

SourceForge.net noreply at sourceforge.net
Thu Feb 17 18:15:31 CET 2005


Patches item #1100942, was opened at 2005-01-12 14:53
Message generated for change (Comment added) made by josh-sf
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1100942&group_id=5470

Category: Modules
>Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Josh (josh-sf)
Assigned to: Nobody/Anonymous (nobody)
Summary: datetime.strptime constructor added

Initial Comment:
Alllow creating new datetime objects by parsing date
strings.

datetime already has strftime, so adding strptime is
logical.

The new constructor is equivalent to
datetime(*(time.strptime(date_string, format)[0:6])).

Patch includes documentation and unit test.

----------------------------------------------------------------------

>Comment By: Josh (josh-sf)
Date: 2005-02-17 17:15

Message:
Logged In: YES 
user_id=1194964

The first patch has been applied, now just the second needs
to be. (strptime2.diff).

That adds support for date and time as well as datetime, as
per alanvgreen's suggestion.

----------------------------------------------------------------------

Comment By: Josh (josh-sf)
Date: 2005-02-02 00:50

Message:
Logged In: YES 
user_id=1194964

Regarding support by datetime.time and datetime.date, if a
date component or a time component is specified,
respectively, do you think that we should raise an
exception? or should we just ignore it?

----------------------------------------------------------------------

Comment By: Alan Green (alanvgreen)
Date: 2005-01-25 12:05

Message:
Logged In: YES 
user_id=1174944

This patch will be welcomed by all of that have had to write
"datetime(*(time.strptime(date_string, format)[0:6]))".

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?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1100942&group_id=5470


More information about the Patches mailing list