Fix #2848: avoid overflow during time calculation