Clean merge of improved datetime handling code