[issue10427] 24:00 Hour in DateTime

Mark Dickinson report at bugs.python.org
Sun Nov 21 21:48:54 CET 2010

Mark Dickinson <dickinsm at gmail.com> added the comment:

> As you make progress on the patch, you will face more questions.

Well, if all that's wanted is for hour==24 to be legal on input, with the datetime object itself being automatically normalized at creation time, then the choices seem simple:  e.g.,

> For example, what should datetime(y, m, d, 24).date() return?  date(y,
> m, d) or date(y, m, d) + timedelta(1)?

The latter, since the two datetime objects would be indistinguishable...

> Should strptime() parse '24' as a valid %H field?

I'd say yes, provided that any minute, second or subsecond fields are all zero.

FWIW, I'm in the camp that says hour==24 should only be legal if all values for smaller time units are zero.

If a datetime object created with 'hour==24' doesn't immediately normalize itself, then I agree there are going to be a lot of hairy questions...

nosy: +mark.dickinson

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list