backport time_spec improvements from upstream