--- gatherHeaderDoc.pl.orig	2009-04-17 17:28:59.000000000 -0700
+++ gatherHeaderDoc.pl	2010-08-02 14:54:01.000000000 -0700
@@ -76,7 +76,7 @@
 
 # Modules specific to gatherHeaderDoc
 use HeaderDoc::DocReference;
-use HeaderDoc::Utilities qw(findRelativePath safeName getAPINameAndDisc printArray printHash updateHashFromConfigFiles getHashFromConfigFile quote resolveLinks sanitize);
+use HeaderDoc::Utilities qw(findRelativePath safeName getAPINameAndDisc printArray printHash updateHashFromConfigFiles getHashFromConfigFile quote resolveLinks sanitize getDefaultEncoding);
 $HeaderDoc::modulesPath = $INC{'HeaderDoc/Utilities.pm'};
 $HeaderDoc::modulesPath =~ s/Utilities.pm$//s;
 # print "MP: ".$HeaderDoc::modulesPath."\n";
@@ -213,12 +213,20 @@
 
 use HeaderDoc::APIOwner;
 
-HeaderDoc::APIOwner->fix_date();
+my $tocEncoding = getDefaultEncoding();
+
+if (defined ($config{"tocTemplateEncoding"}) && length($config{"tocTemplateEncoding"})) {
+	$tocEncoding = $config{"tocTemplateEncoding"}
+}
+
+HeaderDoc::APIOwner::fix_date($tocEncoding);
 
 my ($sec,$min,$hour,$mday,$mon,$yr,$wday,$yday,$isdst) = localtime(time());
 my $yearStamp = strftime("%Y", $sec, $min, $hour,
 	$mday, $mon, $yr, $wday, $yday, $isdst);
-my $dateStamp = HeaderDoc::HeaderElement::strdate($mon, $mday, $yr + 1900);
+my $dateStamp = HeaderDoc::HeaderElement::strdate($mon, $mday, $yr + 1900, $tocEncoding);
+
+# die("DS: $dateStamp\n");
 
 if (defined $config{"styleImports"}) {
     $HeaderDoc::styleImports = $config{"styleImports"};
--- headerDoc2HTML.config.orig	2009-04-17 17:28:59.000000000 -0700
+++ headerDoc2HTML.config	2010-08-02 15:03:43.000000000 -0700
@@ -15,6 +15,8 @@
 stripDotH => 1
 TOCTemplateFile => toctemplate.html functions.tmpl constants.tmpl datatypes.tmpl mpindex.tmpl
 dateFormat => %F
+# tocTemplateEncoding => UTF-8
+# tocTemplateEncoding => iso-8859-1
 styleSheetExtrasFile => stylesheet_adds
 externalStyleSheets => /Resources/CSS/frameset_styles.css
 externalTOCStyleSheets => /Resources/CSS/frameset_styles.css
--- headerDoc2HTML.pl.orig	2009-04-13 15:25:14.000000000 -0700
+++ headerDoc2HTML.pl	2010-08-02 14:52:14.000000000 -0700
@@ -196,6 +196,7 @@
     use lib $uninstalledModulesPath;
     use HeaderDoc::Utilities qw(linesFromFile);
     use HeaderDoc::Utilities qw(processTopLevel);
+    use locale;
 
     if ($HeaderDoc::twig_available) {
 	# This doesn't work!  Need alternate solution.
@@ -852,7 +853,7 @@
 } else {
     $HeaderDoc::datefmt = "%B %d, %Y";
 }
-HeaderDoc::APIOwner->fix_date();
+HeaderDoc::APIOwner::fix_date("UTF-8");
 
 if ($config{"textStyle"}) {
 	HeaderDoc::APIOwner->setStyle("text", $config{"textStyle"});
--- Modules/HeaderDoc/APIOwner.pm.orig	2010-08-02 12:07:51.000000000 -0700
+++ Modules/HeaderDoc/APIOwner.pm	2010-08-02 14:55:54.000000000 -0700
@@ -70,7 +70,7 @@
 ($sec, $min, $hour, $dom, $moy, $year, @rest) = localtime($theTime);
 # $moy++;
 $year += 1900;
-my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year);
+my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year, "UTF-8");
 ######################################################################
 
 my $depth = 0;
@@ -156,9 +156,10 @@
 	return $class->{HEADEROBJECT};
 }
 
-sub fix_date
+sub fix_date($)
 {
-    $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year);
+    my $encoding = shift;
+    $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year, $encoding);
     # print STDERR "fixed date stamp.\n";
     return $dateStamp;
 }
@@ -1997,7 +1998,7 @@
 		print STDERR "$fullpath:$linenum: warning: Invalid date (year = $year, month = $month, day = $day). Valid formats are MM-DD-YYYY, MM-DD-YY, and YYYY-MM-DD\n";
 		return $self->{UPDATED};
 	} else {
-		$self->{UPDATED} =HeaderDoc::HeaderElement::strdate($month-1, $day, $year);
+		$self->{UPDATED} =HeaderDoc::HeaderElement::strdate($month-1, $day, $year, $self->encoding());
 	}
     }
     return $self->{UPDATED};
@@ -4919,7 +4920,15 @@
 	my $encoding = shift;
 	$encoding =~ s/^\s*//sg;
 	$encoding =~ s/\s*$//sg;
+
+	# Cowardly refuse a too-simple encoding.
+	if ($encoding eq "ascii") { $encoding = "UTF-8"; }
+
 	$self->{ENCODING} = $encoding;
+
+	# warn("SET ENCODING TO $encoding\n");
+
+	HeaderDoc::APIOwner::fix_date($encoding);
     }
 
     if ($self->{ENCODING}) {
--- Modules/HeaderDoc/AvailHelper.pm.orig	2009-04-10 14:10:44.000000000 -0700
+++ Modules/HeaderDoc/AvailHelper.pm	2010-08-02 14:52:43.000000000 -0700
@@ -64,7 +64,7 @@
 ($sec, $min, $hour, $dom, $moy, $year, @rest) = localtime($theTime);
 # $moy++;
 $year += 1900;
-my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year);
+my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year, "UTF-8");
 ######################################################################
 
 my $depth = 0;
--- Modules/HeaderDoc/Header.pm.orig	2009-04-10 14:10:45.000000000 -0700
+++ Modules/HeaderDoc/Header.pm	2010-08-02 14:52:50.000000000 -0700
@@ -264,7 +264,7 @@
 		print STDERR "$fullpath:$linenum: warning: Invalid date (year = $year, month = $month, day = $day). Valid formats are MM-DD-YYYY, MM-DD-YY, and YYYY-MM-DD\n";
 		return $self->{UPDATED};
 	} else {
-		$self->{UPDATED} = HeaderDoc::HeaderElement::strdate($month-1, $day, $year);
+		$self->{UPDATED} = HeaderDoc::HeaderElement::strdate($month-1, $day, $year, $self->encoding());
 		print STDERR "date set to ".$self->{UPDATED}."\n" if ($localDebug);
 	}
     }
--- Modules/HeaderDoc/HeaderElement.pm.orig	2009-04-17 17:29:02.000000000 -0700
+++ Modules/HeaderDoc/HeaderElement.pm	2010-08-02 15:06:18.000000000 -0700
@@ -31,12 +31,14 @@
 
 package HeaderDoc::HeaderElement;
 
-use HeaderDoc::Utilities qw(findRelativePath safeName getAPINameAndDisc printArray printHash unregisterUID registerUID quote html2xhtml sanitize parseTokens unregister_force_uid_clear dereferenceUIDObject filterHeaderDocTagContents validTag);
+use HeaderDoc::Utilities qw(findRelativePath safeName getAPINameAndDisc printArray printHash unregisterUID registerUID quote html2xhtml sanitize parseTokens unregister_force_uid_clear dereferenceUIDObject filterHeaderDocTagContents validTag getDefaultEncoding);
 use File::Basename;
 use strict;
 use vars qw($VERSION @ISA);
 use POSIX qw(strftime mktime localtime);
 use Carp qw(cluck);
+use locale;
+use Encode qw(encode decode);
 
 $HeaderDoc::HeaderElement::VERSION = '$Revision: 1.56 $';
 
@@ -2947,7 +2949,7 @@
 		warn "$fullpath:$linenum: warning: Valid formats are MM-DD-YYYY, MM-DD-YY, and YYYY-MM-DD\n";
 		return $self->{UPDATED};
 	} else {
-		$self->{UPDATED} = HeaderDoc::HeaderElement::strdate($month-1, $day, $year);
+		$self->{UPDATED} = HeaderDoc::HeaderElement::strdate($month-1, $day, $year, $self->encoding());
 		print STDERR "date set to ".$self->{UPDATED}."\n" if ($localdebug);
 	}
     }
@@ -3047,11 +3049,12 @@
 }
 
 # /*! strdate WARNING: Month is 0-11, not 1-12. */
-sub strdate
+sub strdate($$$$)
 {
     my $month = shift;
     my $day = shift;
     my $year = shift;
+    my $encoding = shift;
     my $format = $HeaderDoc::datefmt;
     if (!defined $format) {
 	$format = "%B %d, %Y";
@@ -3061,6 +3064,17 @@
     my ($sec,$min,$hour,$mday,$mon,$yr,$wday,$yday,$isdst) = localtime($time_t);
     my $time = strftime($format, $sec, $min, $hour,
 	$mday, $mon, $yr, $wday, $yday, $isdst);
+
+    my $current_encoding = getDefaultEncoding();
+
+    # die("CURENC: ".$current_encoding);
+
+    # cluck("TIME: $time ENC: $encoding");
+
+    my $perltimestring = decode($current_encoding, $time);
+
+    return encode($encoding, $perltimestring);
+
     return $time;
 
     # print STDERR "format $format\n";
@@ -4797,7 +4811,7 @@
     	}
         $compositePageString .= "<copyrightinfo>&#169; $copyrightOwner</copyrightinfo>\n" if (length($copyrightOwner));
 
-	my $dateStamp = $self->fix_date();
+	my $dateStamp = HeaderDoc::APIOwner::fix_date($self->encoding());
 	$compositePageString .= "<timestamp>$dateStamp</timestamp>\n" if (length($dateStamp));
     }
 
--- Modules/HeaderDoc/LineRange.pm.orig	2009-04-10 14:10:45.000000000 -0700
+++ Modules/HeaderDoc/LineRange.pm	2010-08-02 14:52:59.000000000 -0700
@@ -64,7 +64,7 @@
 ($sec, $min, $hour, $dom, $moy, $year, @rest) = localtime($theTime);
 # $moy++;
 $year += 1900;
-my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year);
+my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year, "UTF-8");
 ######################################################################
 
 my $depth = 0;
--- Modules/HeaderDoc/MacroFilter.pm.orig	2009-04-13 15:39:09.000000000 -0700
+++ Modules/HeaderDoc/MacroFilter.pm	2010-08-02 14:53:03.000000000 -0700
@@ -77,7 +77,7 @@
 ($sec, $min, $hour, $dom, $moy, $year, @rest) = localtime($theTime);
 # $moy++;
 $year += 1900;
-my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year);
+my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year, "UTF-8");
 ######################################################################
 
 #insert end
--- Modules/HeaderDoc/TypeHelper.pm.orig	2009-04-10 14:10:47.000000000 -0700
+++ Modules/HeaderDoc/TypeHelper.pm	2010-08-02 14:53:08.000000000 -0700
@@ -64,7 +64,7 @@
 ($sec, $min, $hour, $dom, $moy, $year, @rest) = localtime($theTime);
 # $moy++;
 $year += 1900;
-my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year);
+my $dateStamp = HeaderDoc::HeaderElement::strdate($moy, $dom, $year, "UTF-8");
 ######################################################################
 
 my $depth = 0;
--- Modules/HeaderDoc/Utilities.pm.orig	2009-04-13 15:25:17.000000000 -0700
+++ Modules/HeaderDoc/Utilities.pm	2010-08-02 14:57:22.000000000 -0700
@@ -56,7 +56,7 @@
 	     filterHeaderDocComment filterHeaderDocTagContents processTopLevel
 	     processHeaderComment getLineArrays objectForUID
 	     loadHashes saveHashes getAbsPath allow_everything
-	     getAvailabilityMacros);
+	     getAvailabilityMacros getDefaultEncoding );
 
 my %uid_list_by_uid = ();
 my %uid_list = ();
@@ -2869,6 +2869,26 @@
     }
 }
 
+sub getDefaultEncoding
+{
+    my $current_encoding = $ENV{LC_ALL};
+    if (!$current_encoding) {
+	$current_encoding = $ENV{LC_TIME};
+    }
+    if (!$current_encoding) {
+	$current_encoding = $ENV{LANG};
+    }
+
+    if ($current_encoding =~ /\./) {
+	$current_encoding =~ s/^.*\.//g;
+    } else {
+	# The OS doesn't provide an encoding.  Guess.
+	$current_encoding = "ISO8859-1";
+    }
+
+    return $current_encoding;
+}
+
 
 1;
 
--- Modules/HeaderDoc/HeaderElement.pm.orig	2010-08-02 15:12:22.000000000 -0700
+++ Modules/HeaderDoc/HeaderElement.pm	2010-08-02 20:04:16.000000000 -0700
@@ -6093,4 +6093,15 @@
 		}
 }
 
+# /*!
+#       @abstract
+#           Returns the character set encoding of the enclosing
+#           file.
+#  */
+sub encoding
+{
+	my $self = shift;
+	return $self->apiOwner()->encoding();
+}
+
 1;
