HTML and CSS Reference
In-Depth Information
The JavaScript date object was modelled on the Date class in Java. It was such a
direct copy that it even included the same bugs related to Y2K. Thankfully these
have been resolved long ago.
Download the latest version, add it to the scripts folder, and then import it into the
tasks.html page:
<script src="scripts/date.js"></script>
Now, refresh the tasks.html page in the browser and open the console, you can now use
function calls such as this:
> (2).months().ago()
> (3).days().fromNow();
As you can see, this is a very intuitive date library, and is far superior to the inbuilt library.
We can now add the following function to tasks-controlller.js immediately after the
clearTasks function we just added:
function renderTable() {
$.each($(taskPage).find('#tblTasks tbody tr'), function(idx, row) {
var due = Date.parse($(row).find('[datetime]').text());
if (due.compareTo( < 0) {
} else if (due.compareTo((2).days().fromNow()) <= 0) {
This will iterate through all the rows in the table and extract their date from the attribute
called datetime (you will remember that this conformed to the ISO date standard, therefore
it can be parsed directly without having to specify its format).
Search WWH ::

Custom Search