better implementation of date min/max