ToDoLister – Dates

ToDoLister is my personal side project which I started developing because I was missing some features in other To Do apps. In this post I’ll focus on generating a deadline from user’s input.

How it works from outside

There are several standards how to write dates around the world. My favorite is mm/dd/yy which is not practical to use in Europe where I live at the moment. Some people around here will use dd/mm/yy format and that confuses me.

Out of those two there’s allowed only the first format to be used. There may be plans in the future to allow both when there will be settings page. But that’s somewhere around implementing timezones in date formats, 6:00 mm/dd/yy CET, far far away.

At the moment there are implemented some most common date formats

  • mm/dd/yy
  • dd. MM. yyyy
  • dd. MM. yy
  • dd November 2014

There are also deadlines with specific times. You just need to add hh:mm before the date to work.

ToDoLister supports reoccurring tasks with keyword ev or every.


Calculating deadline is handled by a class called TDLDeadline. At the moment due to a previous design decision constructor sets deadline to value of -1.

Initial parsing of the user’s input is done in a function fromForm :

All decisions are based on regular expression matches. More specific, in this case date formats with time, are matched before less specific.

One time tasks

In that snippet there are two case I haven’t talked about before. The first one is today and the other is tomorrow. These two are simplest functions in this class:

There’s only a PHP function mktime to generate deadline. Other functions aren’t that simple. There’s a need for further parsing of the date format and validation of the date.

As in previous example here are two cases. One with time and one without. My decision to put these two together was to bundle similar cases. Both cases end up calling function makeDeadlineWithTime where the date is validated before calculating the deadline:

Repeatable task

Repeatable tasks are a bit different compared to non-repeatable ones. Currently there’s no keyword starting which would complicate things in a sense that base date wouldn’t be a today but would have to be parsed separately.

Let’s start from the end this time. Months have this not so nice feature. They can be grouped by length into three groups, 31 days, 30 day and February. What will happen when there’s a repeatable task for every 31st of the month. There are two solutions:

  • Some months will be skipped
  • If there is no 31st then it’ll have on 30th, 29th or 28th
The reason why this function seems a bit complicated is the need to know which day is today. In case the day is yet to come it is straight forward. In other cases there need to be some calculations done.

There is a special case called everyDay. This function is divided into two because second part takes a lot of space.


This is the most interesting in the TDLDeadline class I could’ve shown at the moment. There will be more to come when I’ll get to implementing other keywords in the future.

ToDoLister on GitHub