sophia: refactor time routines; support Darwin build