Calendar WIP

This replaces #1260, but was itself replaced by #1316.

I rebased and cleaned up the history for the datepicker branch and then did the same for #1260. However, I was only able to do minor cleanup in this branch because the first commit causes several test failures and I wanted to be able to comment on stuff before I started making major changes to the history. Especially since it's not as easy to clean up as the datepicker branch.