Working out the earliest date(s) from an array of timestamps and applying a class to reflect this
<p>I am having trouble trying to work out how I can add a class of new to the most recent date(s) from my mini films object. The object has a released key that has a timestamp as its value, I've written a function that basically breaks this timestamp up to focus on the date but now Im not very sure of the following a) where should I run this function? do I start to run this function after the templating has been done and then add script that compares each date and then works out which date is the most recent? Sorry at the moment I'm just a little confused how to achieve this?</p>

<p>Do I do the check inside the templating loop? Or do I do it before or after?</p>

<p>Do I loop the dates first working out which is the earliest, then run another loop that works out how many items have this date before going on to add the class?</p>

<p><strong>JS</strong></p>

<pre><code>data = {
    "films": [
        {
        "id": "1",
        "title": "The Shawshank Redemption",
        "description": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.",
        "released": "2012-09-17 00:00:00"},
    {
        "id": "2",
        "title": "The Godfather",
        "description": "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.",
        "released": "2012-09-17 00:00:00"},
    {
        "id": "3",
        "title": "The Godfather: Part II",
        "description": "The early life and career of Vito Corleone in 1920s New York is portrayed while his son, Michael, expands and tightens his grip on his crime syndicate stretching from Lake Tahoe, Nevada to pre-revolution 1958 Cuba.",
        "released": "2012-09-17 00:00:00"},
    {
        "id": "4",
        "title": "Pulp Fiction",
        "description": "The lives of two mob hit men, a boxer, a gangster's wife, and a pair of diner bandits intertwine in four tales of violence and redemption.",
        "released": "2012-09-23 00:00:00"},
    {
        "id": "5",
        "title": "The Good, the Bad and the Ugly",
        "description": "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.",
        "released": "2012-09-25 00:00:00"},
    {
        "id": "6",
        "title": "12 Angry Men",
        "description": "A dissenting juror in a murder trial slowly manages to convince the others that the case is not as obviously clear as it seemed in court.",
        "released": "2012-09-27 00:00:00"}
    ]
}

function formatDate(timeStamp) {
    var timestampParts = timeStamp.split(' ');

    return timestampParts[0];
}

for (var i = 0, len = data.films.length; i &lt; len; i++) {
    var tmp = '&lt;li class="film"&gt;&lt;h2&gt;' + data.films[i].title + '&lt;/h2&gt;&lt;p&gt;' + data.films[i].description + '&lt;/p&gt;&lt;small&gt;' + formatDate(data.films[i].released) + '&lt;/small&gt;&lt;/li&gt;';

    //console.log(formatDate(data.films[i].released));

    $('#list').append(tmp);
}​
</code></pre>

<p><strong>JS Fiddle</strong>
<a href="http://jsfiddle.net/MA9YR/14/" rel="nofollow">http://jsfiddle.net/MA9YR/14/</a></p>
