Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java	(revision 23937)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java	(revision 23938)
@@ -68,5 +68,8 @@
     /** time when this collection was built */
     protected long lastmodified = 0;
-    
+    /** earliestDatestamp of this collection. Necessary for OAI */
+    protected long earliestDatestamp = 0;
+
+
     /** An element containing the serviceRackList element of buildConfig.xml, used to determine whether it contains
      *  the OAIPMH serviceRack 
@@ -133,8 +136,14 @@
 	return is_public;
     }
-    //used by the OAIReceptionist to find out the earliest datestamp amongst all oai collections in the repository
+    // Not used anymore by the OAIReceptionist to find out the earliest datestamp 
+    // amongst all oai collections in the repository. May be useful generally.
     public long getLastmodified() {
       return lastmodified;
     }
+    //used by the OAIReceptionist to find out the earliest datestamp amongst all oai collections in the repository
+    public long getEarliestDatestamp() {
+	return earliestDatestamp;
+    }
+
     /** whether the service_map in ServiceCluster.java contains the service 'OAIPMH'
      *  11/06/2007 xiao
@@ -179,5 +188,5 @@
 	    build_config_elem = build_config_doc.getDocumentElement();
 	}
-  
+
 	lastmodified = build_config_file.lastModified();
   
@@ -264,4 +273,26 @@
       } else {
 	has_oai = true;
+	
+	// extract earliestDatestamp from the buildconfig.xml for OAI
+	Element metadata_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
+
+	if(metadata_list != null) {
+	    NodeList children = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM); 
+	           // can't do getChildNodes(), because whitespace, such as newlines, creates Text nodes
+	    for (int i = 0; i < children.getLength(); i++) {
+		Element metadata = (Element)children.item(i);
+		if(metadata.getAttribute(GSXML.NAME_ATT).equals(OAIXML.EARLIEST_DATESTAMP)) {
+		    String earliestDatestampStr = GSXML.getValue(metadata);
+		    if(!earliestDatestampStr.equals("")) {
+			earliestDatestamp = Long.parseLong(earliestDatestampStr);
+		    }
+		    break; // found a metadata element with name=earliestDatestamp in buildconfig
+		}
+	    }
+	}
+	
+	// If at the end of this, there is no value for earliestDatestamp, print out a warning
+	logger.warn("No earliestDatestamp in buildConfig.xml for collection: " + this.cluster_name + ". Defaulting to 0.");
+
       }
     } else { // no list of services (no ServiceRackList), so no oai_service_rack either
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java	(revision 23937)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java	(revision 23938)
@@ -621,6 +621,8 @@
           //The collection name is returned as site_name:coll_name, which is in fact the set specification
           ane.setAttribute(GSXML.NAME_ATT, site_name + ":" + col_name);
-          ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
-          
+          ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified()); 
+	       // lastmodified not of use anymore for OAI, perhaps useful as general information
+	  ane.setAttribute(OAIXML.EARLIEST_DATESTAMP, "" + c.getEarliestDatestamp()); // for OAI
+
           this.oai_collection_list.appendChild(ane);
           //logger.info(GSXML.xmlNodeToString(oai_collection_list));
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java	(revision 23937)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java	(revision 23938)
@@ -296,5 +296,5 @@
        *  Use the time value plus the current system time to get the expiration date string.
        */
-      String expiration_date = OAIXML.getTime(System.currentTimeMillis() + OAIXML.getTokenExpiration());
+	String expiration_date = OAIXML.getTime(System.currentTimeMillis() + OAIXML.getTokenExpiration()); // in milliseconds
       token.setAttribute(OAIXML.EXPIRATION_DATE, expiration_date);
     }
@@ -1034,18 +1034,21 @@
     // See OAIConfig.xml
     // dynamically works out what the earliestDateStamp is, since it varies by collection
+    // returns this time in *milliseconds*.
     protected long getEarliestDateStamp(NodeList oai_coll) {
 	//do the earliestDatestamp
-	long lastmodified = System.currentTimeMillis();	
+	long earliestDatestamp = System.currentTimeMillis();	
 	int oai_coll_size = oai_coll.getLength();
 	if (oai_coll_size == 0) {
 	    logger.info("returned oai collection list is empty. Setting repository earliestDatestamp to be 1970-01-01.");
-	    lastmodified = 0;
+	    earliestDatestamp = 0;
 	}
-	//the collection build time is determined by the last modified time of the buildConfig.xml file
+	// the earliestDatestamp is now stored as a metadata element in the collection's buildConfig.xml file
+	// we get the earliestDatestamp among the collections
 	for(int i=0; i<oai_coll_size; i++) {
-	    long coll_build_time = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.LASTMODIFIED));
-	    lastmodified = (lastmodified > coll_build_time)? coll_build_time : lastmodified;
+	    long coll_earliestDatestamp = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.EARLIEST_DATESTAMP));
+	    earliestDatestamp = (earliestDatestamp > coll_earliestDatestamp)? coll_earliestDatestamp : earliestDatestamp;
 	}
-	return lastmodified;
+
+	return earliestDatestamp*1000; // converting from seconds to milliseconds
     }
 }
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java	(revision 23937)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java	(revision 23938)
@@ -253,8 +253,8 @@
 
     ArrayList keys = new ArrayList(info.getKeys());
-    String lastmodified = "";
-    if(keys.contains(OAIXML.LASTMODIFIED)) {
-      lastmodified = info.getInfo(OAIXML.LASTMODIFIED);
-      lastmodified = OAIXML.getTime(Long.parseLong(lastmodified)*1000); // java wants dates in milliseconds
+    String oailastmodified = "";
+    if(keys.contains(OAIXML.OAI_LASTMODIFIED)) {
+      oailastmodified = info.getInfo(OAIXML.OAI_LASTMODIFIED);
+      oailastmodified = OAIXML.getTime(Long.parseLong(oailastmodified)*1000); // java wants dates in milliseconds
     }
 
@@ -262,5 +262,5 @@
     Element record = OAIXML.createElement(OAIXML.RECORD);
     //compose the header element
-    record.appendChild(createHeaderElement(oid, lastmodified));      
+    record.appendChild(createHeaderElement(oid, oailastmodified));      
     //compose the metadata element
     record.appendChild(createMetadataElement(prefix, info, metadata_format));
@@ -332,11 +332,11 @@
       }
       ArrayList keys = new ArrayList(info.getKeys());
-      String lastmodified = "";
-      if(keys.contains(OAIXML.LASTMODIFIED)) {
-        lastmodified = info.getInfo(OAIXML.LASTMODIFIED);
-	lastmodified = OAIXML.getTime(Long.parseLong(lastmodified)*1000); // java wants dates in milliseconds
+      String oailastmodified = "";
+      if(keys.contains(OAIXML.OAI_LASTMODIFIED)) {
+        oailastmodified = info.getInfo(OAIXML.OAI_LASTMODIFIED);
+	oailastmodified = OAIXML.getTime(Long.parseLong(oailastmodified)*1000); // java wants dates in milliseconds
       }
       
-      Date this_date = OAIXML.getDate(lastmodified);        
+      Date this_date = OAIXML.getDate(oailastmodified);        
       if (from_date != null) {
         if(this_date.before(from_date)) {
@@ -350,5 +350,5 @@
       }      
       //compose the header element and append it
-      list_identifiers.appendChild(createHeaderElement(oid, lastmodified));      
+      list_identifiers.appendChild(createHeaderElement(oid, oailastmodified));      
     }//end of for(int i=0; i<oid_list.size(); i++) of doing thru each record
     
@@ -418,11 +418,11 @@
       }
       ArrayList keys = new ArrayList(info.getKeys());
-      String lastmodified = "";
-      if(keys.contains(OAIXML.LASTMODIFIED)) {
-        lastmodified = info.getInfo(OAIXML.LASTMODIFIED);
-	lastmodified = OAIXML.getTime(Long.parseLong(lastmodified)*1000); // java wants dates in milliseconds
+      String oailastmodified = "";
+      if(keys.contains(OAIXML.OAI_LASTMODIFIED)) {
+        oailastmodified = info.getInfo(OAIXML.OAI_LASTMODIFIED);
+	oailastmodified = OAIXML.getTime(Long.parseLong(oailastmodified)*1000); // java wants dates in milliseconds
       }
       
-      Date this_date = OAIXML.getDate(lastmodified);        
+      Date this_date = OAIXML.getDate(oailastmodified);        
       if (from_date != null) {
         if(this_date.before(from_date)) {
@@ -439,5 +439,5 @@
       list_records.appendChild(record);
       //compose the header element
-      record.appendChild(createHeaderElement(oid, lastmodified));      
+      record.appendChild(createHeaderElement(oid, oailastmodified));      
       //compose the metadata element
       record.appendChild(createMetadataElement(prefix, info, metadata_format));
@@ -501,5 +501,5 @@
   /** create a header element used when processing requests like ListRecords/GetRecord/ListIdentifiers
    */
-  private Element createHeaderElement(String oid, String lastmodified) {    
+  private Element createHeaderElement(String oid, String oailastmodified) {    
         Element header = OAIXML.createElement(OAIXML.HEADER);
         Element identifier = OAIXML.createElement(OAIXML.IDENTIFIER);
@@ -510,5 +510,5 @@
         header.appendChild(set_spec);
         Element datestamp = OAIXML.createElement(OAIXML.DATESTAMP);
-        GSXML.setNodeText(datestamp, lastmodified);
+        GSXML.setNodeText(datestamp, oailastmodified);
         header.appendChild(datestamp);
         return header;
@@ -656,4 +656,7 @@
 <contains>".1;".2;".3;".4;".5;".6;".7;".8;".9
 <docnum>349
+<oailastmodified>1303283795
+<lastmodifieddate>20110412
+<oailastmodifieddate>20110420
 ----------------------------------------------------------------------
      */
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java	(revision 23937)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java	(revision 23938)
@@ -112,4 +112,5 @@
     public static final String OAI = "OAI";
     public static final String OAI_DASH_PMH = "OAI-PMH";
+    public static final String OAI_LASTMODIFIED = "oailastmodified";
     public static final String OAIPMH = "OAIPMH";
     public static final String OAI_RESUMPTION_TOKENS = "OAIResumptionTokens";
