The Lorentzian index theorem and its local version