added function to deal with duration instead of timestamps