The various `trac.util.datefmt` utilities are using the above function so that they're robust w.r.t. non-migrated plugins, but they already document the stricter requirement to accept only `datetime` objects or `None` (the current time), which will be enforced in [milestone:0.12].
I also added a few unit tests.
Fixes #4547, based on Dave Abrahams' original patch.