date matching patterns algorithm