Unify set time code. Introduce mode variable.