UPDATE: PTTtrip.getStartTime(Day) now uses a NEW method PTTrip.getStartDay(Day) which returns the day ("today" or "yesterday") for the start of the trip along with the time.
Similaraly for PTTrip.getEndTime(Day) (but it's "today" or "tomorrow"). The returned value in both cases is a datetime.combine(datetime, time) object, so trip durations can be reliably found for any trip.
The last (and irresolvable) vestige of the "midnight bug" is that a trip that runs over midnight for two consecutive nights with the same trip_id has ambiguous start and end dates.
No cases of this have yet been found, but exceptions will be raised if it is, and a decision on how to handle this will be made then. This code is provided "as is" with this in mind.