it looks like this function could be split into 3-4 separate functions. Specially when getting/validating time offsets and checking if time is valid / getting each time fragment.