An action founded on the design, planning, or construction of an improvement to real property, with the time running from the date the authority having jurisdiction issues a temporary certificate of occupancy, a certificate of occupancy, or a certificate of completion, or the date of abandonment of construction if not completed, whichever date is earliest; except that, when the action involves a latent defect, the time runs from the time the defect is discovered or should have been discovered...