Q:

time scheduled to-do list loop calculation in php - (7 mins = 13:04 - 13:11 and so on)

I probably have the most difficult challange in the php history. I´m making
a light to-do list system - I enter the task and estimated minutes
and the task appears in a list below.
Just two form fields "task" and "minutes" and button.
So now (when the time is 2013-12-07 23:01) and I insert
"send the files to Bill" and 7 minutes the task appears as
"Send the files to Bill" 23:01 - 23:08
.. the task list goes down so if next is "start on project X" and 40 minutes
it will appear under the first project
"Send the files to Bill" 23:01 - 23:08
"start on project X" 23:09 - 23:49
I´ve managed the first taks by creating timestamp and output (H:i) by adding the minutes.
I don´t what is the best approach for the calculation
The function I want is when I have a long list and if I cancel one project
all the list will auto-calculate the schedule so next thing is the next task
Will I have to use start timestamp and end timestamp for everything and update all the timestamps or can I make every task being chain reaction of the sum of the task before (ext.7 min + 40 min + 12 min + 9 min) with on start date?
This sounds like it´s very easy but it appears much more difficult than I expected

A:

You should store duration in db, and have a DateTime as your starting point for all the computation.
Then, having that, you can just play with DateTime & DateInterval.
// examples
$date = DateTime::createFromFormat('Y-m-d H:i', '2013-12-07 23:01');

// add 7 minutes to it and echo result
$date->add(new DateInterval('PT7M'));
echo $date->format('Y-m-d H:i');

// add 40 minutes to it and echo result
$date->add(new DateInterval('PT40M'));
echo $date->format('Y-m-d H:i');

and so on...

