a null pointer is valid here and indicates that the current time should be used. based on patch by Felix Janda, simplified.