How do I make block only visible if the 'field_date_value' is in the past? What code do I use on a D7 website if I want a block only to be visible if the field_date_value of a date node is in the past?

On a D6 site, I had this working for all date nodes:

$match = FALSE;
$types = array('date' =&gt; 1);
if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1) )) {
  $nid = arg(1);
  $node = node_load(array('nid' =&gt; $nid));
  $type = $node-&gt;type;
  if (isset($types[$type])) {
    $match = TRUE;
  }
}
return $match;


But this code does not work on a D7 site. Besides, all that I want is it to only show a date node when the date in the past. (For a past event.)
Pretend you need a block to be visible on a node depending on the value of a date field on the node.

A good example is a website that lists classes as nodes. You want a block visible only on class nodes. You also only want that block visible if the date of the class is in the future.

The classes are created by making nodes of a custom content type called "class". Each class node contains an date field called "class_date" that contains the date of the first day of the class. The date field is a regular ISO date field type. This PHP snippet returns TRUE if the node is a "class" and the "class_date" field is in the future and the block is then visible.

&lt;?php
$node = menu_get_object();
if ( !empty($node)  &amp;&amp; $node-&gt;type == 'class' ) {
  if ( !empty($node-&gt;field_class_date) &amp;&amp; !empty($node-&gt;field_class_date['und']) &amp;&amp; !empty($node-&gt;field_class_date['und'][0]) ) {
     $parts = explode('T', $node-&gt;field_class_date['und'][0]['value']);
     $date_parts =  explode('-', $parts[0]);
     $class_date = $date_parts[1] . '/' . $date_parts[2] . '/' . $date_parts[0] . ' ' .  $parts[1];
     $on = strtotime($class_date);
     $now = time();
     if ( $on &gt;= $now ) {
        return TRUE;
     }
  }
}
return FALSE;
?&gt;