Paul Ganssle <p.gans...@gmail.com> added the comment:

Hi Abhisek,

This is actually the expected / intended behavior, and it is documented under 
"strptime() and strftime() behavior": 
https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior 
(which is linked to by the time.strftime documentation: 
https://docs.python.org/3/library/datetime.html#datetime.datetime.strftime . 
The relevant section is:

  For time objects, the format codes for year, month, and day should not be 
used, as time objects have no such values. If they’re used anyway, 1900 is 
substituted for the year, and 1 for the month and day.

If I were designing `datetime.time.strftime` from scratch, my instinct would be 
to throw an error in this case, but my philosophy on parsing interfaces tends 
towards the stricter side. At this point, I think it would do more harm than 
good to change this behavior. I imagine that the motivation is something like 
the Robustness Principle ( https://en.wikipedia.org/wiki/Robustness_principle 
), but I wasn't involved in the original design so I can't be sure.

Thank you for taking the time to make a bug report, it's very appreciated even 
when it turns out to not be a bug.

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38082>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to