lib/duration: factor into a lib, and add it for old plugin