PEP 321: Date/Time Parsing and Formatting

Gerrit Holl gerrit at
Wed Nov 19 18:42:58 CET 2003

A.M. Kuchling wrote:
> Let's assume we add a strptime() method to date, time, and datetime. What
> happens when you provide a time or date where it's not useful e.g.
> date.strptime(..., '1992-10-15 12:05:32')?  Does it raise an exception? Does
> it silently ignore the time data?  Or is it illegal to use time-related
> specifiers such as %H with date.strptime, or date-related ones such as %m
> with time.strptime?

I don't see the difference between the first and the last one. I am for
raising an exception: date.strptime only knows about date-formatting codes,
while time.strptime only knows about time-formatting codes. If I Recall
Correctly, the current time.strptime is completely relying on the underlying

> > I prefer solution 2. I think it is the most object-oriented way. And we
> So do we have one parsing method -- strptime() -- or several, one for each
> variant date format?  Perhaps the simplest thing is to just add strptime()
> for now.

I think only one.

> > though. Shouldn't datetime be a subclass of both date and time?
> Probably not; a time represents a time independent of any particular day, 
> while a datetime is certainly tied to a day, so a subclass relationship
> doesn't make sense.

Hmm... but it feels like date+time == datetime. Doesn't a subclass
relationship makes sense, because datetime has the time information from
the time class and the date information from the date class?


282. If a slave say to his master: "You are not my master," if they
convict him his master shall cut off his ear.
          -- 1780 BC, Hammurabi, Code of Law
Asperger Syndroom - een persoonlijke benadering:
Kom in verzet tegen dit kabinet:

More information about the Python-list mailing list