Index: main/trunk/greenstone2/perllib/classify/DateList.pm
===================================================================
--- main/trunk/greenstone2/perllib/classify/DateList.pm	(revision 23116)
+++ main/trunk/greenstone2/perllib/classify/DateList.pm	(revision 27308)
@@ -144,5 +144,4 @@
     } 
     
-    #my $date = $doc_obj->get_metadata_element ($doc_obj->get_top_section(), $self->{'metadata'});
     if (!defined $date || $date eq "") {
 	# if this document doesn't contain Date element we won't 
@@ -150,5 +149,5 @@
 	return;
     }
-    
+
     my $sort_other = "";
     if (defined $self->{'sort'} && $self->{'sort'} ne "") {
@@ -161,6 +160,5 @@
 	print $outhandle "WARNING: DateList::classify called multiple times for $doc_OID\n";
     } 
-   
-     
+        
     $self->{'list'}->{$doc_OID} = "$date$sort_other";
 
@@ -237,5 +235,5 @@
 	    }
 	    
-	} else { # don't group - individual years and months
+	} else { # -nogroup - individual years and months
 	    foreach my $classification (@$classlistref) {
 		my $date = $self->{'list'}->{$classification};
@@ -256,11 +254,17 @@
 	    # create hlist of years containing hlists of months
 
+	    my @subclasslist = sort {$a <=> $b} (keys %$classhash);
+	    if ($self->{'reverse_sort'}) {
+		@subclasslist = reverse @subclasslist;
+	    }
 	    
-	    if ($self->{'reverse_sort'}){
-               foreach my $subclass (sort {$b <=> $a} 
-				    (keys %$classhash)){
+	    foreach my $subclass (@subclasslist) {
 		  my $yearclassify = $self->get_entry($subclass, "HList");
-		  foreach my $subsubclass (sort {$b <=> $a} 
-					   (keys %{$classhash->{$subclass}})) {
+		  my @subsubclasslist = sort {$a <=> $b} (keys %{$classhash->{$subclass}});
+		  if ($self->{'reverse_sort'}) {
+		      @subsubclasslist = reverse @subsubclasslist;
+		  }
+
+		  foreach my $subsubclass (@subsubclasslist) {
 		      my $monthname=$subsubclass;
 		      if ($monthname >= 1 && $monthname <= 12) {
@@ -277,34 +281,9 @@
 		  }
 		  push (@{$classifyinfo->{'contains'}}, $yearclassify);
-	      }
-	    }
-	    else{
-		foreach my $subclass (sort {$a <=> $b} 
-				    (keys %$classhash)){
-		    my $yearclassify = $self->get_entry($subclass, "HList");
-		    foreach my $subsubclass (sort {$a <=> $b} 
-					     (keys %{$classhash->{$subclass}})) {
-		      my $monthname=$subsubclass;
-		      if ($monthname >= 1 && $monthname <= 12) {
-			  $monthname="_textmonth" . $monthname . "_";
-		      }
-		      my $monthclassify=$self->get_entry($monthname, $self->{'childtype'});
-		      push (@{$yearclassify->{'contains'}}, $monthclassify);
-		      
-		      foreach my $subsubOID 
-			  (@{$classhash->{$subclass}->{$subsubclass}}) {
-			      push (@{$monthclassify->{'contains'}},
-				    {'OID'=>$subsubOID});
-			  }
-		  }
-		    push (@{$classifyinfo->{'contains'}}, $yearclassify);
-		}
-		
-		
 	    }
 	    
 	    return $classifyinfo;
 	} # nogroup
-    }else {
+    } else {
 	# not by month
 	# first split up the list into separate year classifications
@@ -322,25 +301,15 @@
 	$classhash = $self->compactlist ($classhash);
     }
-
-    if ($self->{'reverse_sort'} && $self->{'nogroup'} ) {
- 	foreach my $subclass (reverse sort keys %$classhash) {
-	    my $tempclassify = $self->get_entry($subclass, $self->{'childtype'});
-	    foreach my $subsubOID (@{$classhash->{$subclass}}) {
-		push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
-	    }
-	    push (@{$classifyinfo->{'contains'}}, $tempclassify);
-	}
-    }
-    else{
-	foreach my $subclass (sort keys %$classhash) {
-	    my $tempclassify = $self->get_entry($subclass, $self->{'childtype'});
-	    foreach my $subsubOID (@{$classhash->{$subclass}}) {
-		push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
-	    }
-	    push (@{$classifyinfo->{'contains'}}, $tempclassify);
-	}
-
-    }
-    
+    my @subclasslist = sort keys %$classhash;
+    if ($self->{'reverse_sort'}) {
+	@subclasslist = reverse @subclasslist;
+    }
+    foreach my $subclass (@subclasslist) {
+	my $tempclassify = $self->get_entry($subclass, $self->{'childtype'});
+	foreach my $subsubOID (@{$classhash->{$subclass}}) {
+	    push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
+	}
+	push (@{$classifyinfo->{'contains'}}, $tempclassify);
+    }
   
     return $classifyinfo;
@@ -363,5 +332,9 @@
     my $min = 10; 
     my $max = 30;
-    foreach my $subsection (sort keys %$classhashref) {
+    my @subsectionlist = sort keys %$classhashref;
+    if ($self->{'reverse_sort'}) {
+	@subsectionlist = reverse @subsectionlist;
+    } 
+    foreach my $subsection (@subsectionlist) {
 	$currentfirstdate = $subsection if $currentfirstdate eq "";
 	if ((scalar (@currentOIDs) < $min) ||
