To Do List Project: Part 8

Today I began straightening out the calculation of total elapsed time for all slices associated with each To Do item. This work included three components: getting the date/time calculations correct and performed consistently (all on the PHP side and none on the JavaScript side), getting the calculations in the right place so they reflect what they’re supposed to reflect, and understanding the scope of PHP variables in different contexts across numerous files and sessions.

The calculation has to be performed for each completed slice when the Update To Do page is first created, and this work is done in the GetToDoSlices.php file. The code has to not update the calculation when a slice has been started but not completed. The code also has to make variables available that store the sums for elapsed hours and minutes, and for the currently effective start time if there is one, so the total elapsed hours and minutes can be displayed on the form in the appropriate spot. Finally, the code, this time in the UpdateStartTime.php and UpdateEndTime.php files, has to be able to mark the time that start and end events happen and update the running total as needed, both on the display and in the database.

You’ve seen a lot of this code already but I’ll just re-list the relevant files here so the action can be tracked. I can verify that it has been tested and works as expected.

Here is the entire GetToDoSlices.php file, where I’ve corrected a mistake.

Here is the UpdateStartTime.php file, which is invoked by clicking on the “Start” button.

Here is the UpdateEndTime.php file, which is invoked by clicking on the “End” button.

Here is the code in the UpdateToDo.php file that displays the accumulated hours and minutes for the current To Do item when the page is first created.

Here is the embedded JavaScript that updates the accumulated hours and minutes when the “End” button is clicked to complete a time slice.

Getting the date and time ops right is straightforward as is getting the summations and calculations right. That’s standard think and tweak. The value of this exercise for me is getting the “isness” of PHP, which in this case means getting a feel for what variables are available where. For this exercise I was able to declare and set things like $startTime, $endTime, $totalTime, $elapsedHours, and elapsedMinutes in one file and successfully refer to them in a different file without including a header or explicit link in the code. The link has to exist implicitly, and I don’t know exactly how yet, but at least I know the next set of concepts to look out for as I proceed.

How does the system keep track of these values? Is it done session by session with potentially multiple instantiations of each variable but for different users? How does this compare to what is done in Node.js? How the the server executive manage all of this? Inquiring minds wanna know! (yeah, sorry about that…)

Learning any language is an iterative process that you just have to wallow through until you can think in its idiom. You can work through the examples in a book or parrot those in a video course but until you try to change it or write your own you don’t really get the full depth of it, unless the instruction is exceptionally complete, and I’ve never encountered any such instruction in any area of my life. That indicates that there’s only so much complexity people can handle at one time. You have to understand one part before you even understand the questions that come up in the course of learning the next part. I know some instructors shared some advanced concepts in some swing dancing classes I was in that I vaguely remembered but didn’t quite process. Two years later it was all, “Oh now I get what he was talking about there!”

And so it goes. Day by day.

This entry was posted in Software and tagged , . Bookmark the permalink.

Leave a Reply