Index: /main/trunk/greenstone2/perllib/basebuilder.pm
===================================================================
--- /main/trunk/greenstone2/perllib/basebuilder.pm	(revision 23938)
+++ /main/trunk/greenstone2/perllib/basebuilder.pm	(revision 23939)
@@ -560,4 +560,23 @@
 
     $build_cfg->{'infodbtype'} = $self->{'infodbtype'};
+    
+    # write out the earliestDatestamp information needed for OAI
+    my $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives");
+    if(!-d $archivedir) {
+	$archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "export");
+    }    
+    if(-d $archivedir) {
+	my $earliestDatestampFile = &util::filename_cat ($archivedir, "earliestDatestamp");
+	open(FIN,"<$earliestDatestampFile") || die "{common.cannot_open} $earliestDatestampFile: $!\n";
+	my $earliestDatestamp;
+	{
+	    # slurp in file as a single line
+	    local $/ = undef;
+	    $earliestDatestamp = <FIN>;
+	    #&unicode::ensure_utf8(\$earliestDatestamp); # turn any high bytes that aren't valid utf-8 into utf-8.
+	}
+	close(FIN);	
+	$build_cfg->{'earliestDatestamp'} = $earliestDatestamp;
+    }
 
     $self->build_cfg_extra($build_cfg);
Index: /main/trunk/greenstone2/perllib/buildConfigxml.pm
===================================================================
--- /main/trunk/greenstone2/perllib/buildConfigxml.pm	(revision 23938)
+++ /main/trunk/greenstone2/perllib/buildConfigxml.pm	(revision 23939)
@@ -226,4 +226,8 @@
 	&write_line('COLCFG', ["<metadata name=\"infodbType\">", $buildcfg->{"infodbtype"}, "</metadata>"]);
     }
+    if (defined $buildcfg->{'earliestDatestamp'}) {
+	&write_line('COLCFG', ["<metadata name=\"earliestDatestamp\">", $buildcfg->{"earliestDatestamp"}, "</metadata>"]);
+    }
+
     &write_line('COLCFG', ["</metadataList>"]);
 
Index: /main/trunk/greenstone2/perllib/colcfg.pm
===================================================================
--- /main/trunk/greenstone2/perllib/colcfg.pm	(revision 23938)
+++ /main/trunk/greenstone2/perllib/colcfg.pm	(revision 23939)
@@ -225,5 +225,5 @@
 
     return &cfgread::read_cfg_file ($filename, 
-		   q/^(infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
+		   q/^(earliestdatestamp|infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
 		   q/^(indexmap|subcollectionmap|languagemap|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);
 				    
@@ -235,5 +235,5 @@
 
     &cfgread::write_cfg_file($filename, $data,
-	       q/^(infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
+	       q/^(earliestdatestamp|infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
 	       q/^(indexmap|subcollectionmap|languagemap|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);		     
 }
Index: /main/trunk/greenstone2/perllib/doc.pm
===================================================================
--- /main/trunk/greenstone2/perllib/doc.pm	(revision 23938)
+++ /main/trunk/greenstone2/perllib/doc.pm	(revision 23939)
@@ -126,4 +126,24 @@
 
 # set lastmodified for OAI purposes, added by GRB, moved by kjdon
+sub set_oailastmodified {
+    my $self = shift (@_);
+
+    my $source_path = $self->{'terse_source_path'};
+   
+    if (defined $source_path && (-e $source_path)) {
+	my $current_time = time;
+
+	my ($seconds, $minutes, $hours, $day_of_month, $month, $year,
+	    $wday, $yday, $isdst) = localtime($current_time);
+
+	my $date_modified = sprintf("%d%02d%02d",1900+$year,$month+1,$day_of_month);
+
+	$self->add_utf8_metadata($self->get_top_section(), "oailastmodified", $current_time);
+	$self->add_utf8_metadata($self->get_top_section(), "oailastmodifieddate", $date_modified);
+    } 
+}
+
+# no longer used for OAI purposes, since lastmodified is not what we want as the
+# Datestamp of a document. This doc metadata may be useful for general purposes.
 sub set_lastmodified {
     my $self = shift (@_);
Index: /main/trunk/greenstone2/perllib/inexport.pm
===================================================================
--- /main/trunk/greenstone2/perllib/inexport.pm	(revision 23938)
+++ /main/trunk/greenstone2/perllib/inexport.pm	(revision 23939)
@@ -708,5 +708,20 @@
 	}
     }
-    
+
+    # Check for existence of the file that's to contain earliestDateStamp in archivesdir
+    # Do nothing if the file already exists (file exists on incremental build).
+    # If the file doesn't exist, as happens on full build, create it and write out the current datestamp into it
+    # In buildcol, read the file's contents and set the earliestdateStamp in GS2's build.cfg / GS3's buildconfig.xml
+    # In doc.pm have set_oaiLastModified similar to set_lastmodified, and create the doc fields 
+    # oailastmodified and oailastmodifieddate
+    my $earliestDatestampFile = &util::filename_cat($archivedir, "earliestDatestamp");
+    if (!-f $earliestDatestampFile) {
+	my $current_time_in_seconds = time; # in seconds
+	open(FOUT, ">$earliestDatestampFile") || die "{common.cannot_open} $earliestDatestampFile: $!\n";
+	#    (&gsprintf(STDERR, "{common.cannot_open}: $!\n", $earliestDatestampFile) && die);
+	print FOUT $current_time_in_seconds;
+	close(FOUT);
+    }
+
     # now, whichever mode we are in, we can process the entire import folder
     if ((defined $jobs) && ($jobs > 1))
Index: /main/trunk/greenstone2/perllib/plugouts/BasePlugout.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugouts/BasePlugout.pm	(revision 23938)
+++ /main/trunk/greenstone2/perllib/plugouts/BasePlugout.pm	(revision 23939)
@@ -424,5 +424,7 @@
     my ($doc_obj) = @_;
     
+    # for OAI purposes
     $doc_obj->set_lastmodified();
+    $doc_obj->set_oailastmodified();
 
      if ($self->{'group_size'} > 1) {
