Fixed maskDate function to be more flexible.