Implementing a date algorithm