Unifying the Dynkin and Lebesgue-Stieltjes formulae