Backport DateTime 3 compatibility to 1.6 branch

Hi. I backported DateTime 3 compatibility from master (commit dc257b05ef1f7a15ba434802b1dffb502c0cde44) to the 1.6 branch.