refactor code into Date.pm, improve tests