Let smarty decide date formatting rather than date_str
Let smarty decide date formatting rather than date_str

--- a/include/controller/Controller_Commit.class.php
+++ b/include/controller/Controller_Commit.class.php
@@ -11,7 +11,6 @@
  */
 
 require_once(GITPHP_INCLUDEDIR . 'util.file_type.php');
-require_once(GITPHP_INCLUDEDIR . 'util.date_str.php');
 require_once(GITPHP_INCLUDEDIR . 'gitutil.git_diff_tree.php');
 
 /**
@@ -90,8 +89,6 @@
 	protected function LoadData()
 	{
 		$commit = $this->project->GetCommit($this->params['hash']);
-		$ad = date_str($commit->GetAuthorEpoch(), $commit->GetAuthorTimezone());
-		$cd = date_str($commit->GetCommitterEpoch(), $commit->GetCommitterTimezone());
 		$parentObj = $commit->GetParent();
 		if ($parentObj) {
 			$root = "";
@@ -108,14 +105,6 @@
 		if ($parentObj)
 			$this->tpl->assign("parent", $parentObj->GetHash());
 		$this->tpl->assign("commit", $commit);
-		$this->tpl->assign("adrfc2822",$ad['rfc2822']);
-		$this->tpl->assign("adhourlocal",$ad['hour_local']);
-		$this->tpl->assign("adminutelocal",$ad['minute_local']);
-		$this->tpl->assign("adtzlocal",$ad['tz_local']);
-		$this->tpl->assign("cdrfc2822",$cd['rfc2822']);
-		$this->tpl->assign("cdhourlocal",$cd['hour_local']);
-		$this->tpl->assign("cdminutelocal",$cd['minute_local']);
-		$this->tpl->assign("cdtzlocal",$cd['tz_local']);
 		$this->tpl->assign("difftreesize",count($difftree)+1);
 		$difftreelines = array();
 		foreach ($difftree as $i => $line) {

--- a/include/controller/Controller_Commitdiff.class.php
+++ b/include/controller/Controller_Commitdiff.class.php
@@ -10,7 +10,6 @@
  * @subpackage Controller
  */
 
-require_once(GITPHP_INCLUDEDIR . 'util.date_str.php');
 require_once(GITPHP_INCLUDEDIR . 'util.file_type.php');
 require_once(GITPHP_INCLUDEDIR . 'util.prep_tmpdir.php');
 require_once(GITPHP_INCLUDEDIR . 'gitutil.git_diff_tree.php');
@@ -134,9 +133,8 @@
 				if ($rev == $this->params['hash'])
 					break;
 			}
-			$ad = date_str($co->GetAuthorEpoch(), $co->GetAuthorTimezone());
 			$this->tpl->assign("from", $co->GetAuthor());
-			$this->tpl->assign("date",$ad['rfc2822']);
+			$this->tpl->assign("date",$co->GetAuthorEpoch());
 			$this->tpl->assign("subject", $co->GetTitle());
 			if (isset($tagname))
 				$this->tpl->assign("tagname",$tagname);

--- a/include/controller/Controller_Log.class.php
+++ b/include/controller/Controller_Log.class.php
@@ -10,7 +10,6 @@
  * @subpackage Controller
  */
 
-require_once(GITPHP_INCLUDEDIR . 'util.date_str.php');
 require_once(GITPHP_INCLUDEDIR . 'util.age_string.php');
 require_once(GITPHP_INCLUDEDIR . 'gitutil.git_read_revlist.php');
 require_once(GITPHP_INCLUDEDIR . 'gitutil.read_info_ref.php');
@@ -127,7 +126,6 @@
 			if (isset($commit) && strlen($commit) > 1) {
 				$commitline = array();
 				$co = $this->project->GetCommit($commit);
-				$ad = date_str($co->GetAuthorEpoch());
 				$commitline["project"] = $this->project->GetProject();
 				$commitline["commit"] = $commit;
 				if (isset($refs[$commit]))
@@ -135,7 +133,7 @@
 				$commitline["agestring"] = age_string($co->GetAge());
 				$commitline["title"] = $co->GetTitle();
 				$commitline["authorname"] = $co->GetAuthorName();
-				$commitline["rfc2822"] = $ad['rfc2822'];
+				$commitline["authorepoch"] = $co->GetAuthorEpoch();
 				$commitline["comment"] = $co->GetComment();
 				$commitlines[] = $commitline;
 				unset($co);
@@ -174,7 +172,6 @@
 				if (isset($refs[$commit]))
 					$commitline["commitref"] = $refs[$commit];
 				$co = $this->project->GetCommit($commit);
-				$ad = date_str($co->GetAuthorEpoch());
 				$commitline["commit"] = $commit;
 				$age = $co->GetAge();
 				if ($age > 60*60*24*7*2) {

--- a/include/controller/Controller_Project.class.php
+++ b/include/controller/Controller_Project.class.php
@@ -10,7 +10,6 @@
  * @subpackage Controller
  */
 
-require_once(GITPHP_INCLUDEDIR . 'util.date_str.php');
 require_once(GITPHP_INCLUDEDIR . 'util.age_string.php');
 require_once(GITPHP_INCLUDEDIR . 'gitutil.git_read_revlist.php');
 
@@ -86,12 +85,11 @@
 	{
 		$descr = $this->project->GetDescription();
 		$headCommit = $this->project->GetHeadCommit();
-		$commitdate = date_str($headCommit->GetCommitterEpoch(), $headCommit->GetCommitterTimezone());
 		$owner = $this->project->GetOwner();
 		$this->tpl->assign("head", $headCommit->GetHash());
 		$this->tpl->assign("description",$descr);
 		$this->tpl->assign("owner",$owner);
-		$this->tpl->assign("lastchange",$commitdate['rfc2822']);
+		$this->tpl->assign("lastchange",$headCommit->GetCommitterEpoch());
 		if (GitPHP_Config::GetInstance()->HasKey('cloneurl'))
 			$this->tpl->assign('cloneurl', GitPHP_Config::GetInstance()->GetValue('cloneurl') . $this->project->GetProject());
 		if (GitPHP_Config::GetInstance()->HasKey('pushurl'))

--- a/include/controller/Controller_Rss.class.php
+++ b/include/controller/Controller_Rss.class.php
@@ -10,7 +10,6 @@
  * @subpackage Controller
  */
 
-require_once(GITPHP_INCLUDEDIR . 'util.date_str.php');
 require_once(GITPHP_INCLUDEDIR . 'gitutil.git_read_revlist.php');
 require_once(GITPHP_INCLUDEDIR . 'gitutil.git_diff_tree.php');
 
@@ -106,15 +105,10 @@
 			$co = $this->project->GetCommit($commit);
 			if (($i >= 20) && ((time() - $co->GetCommitterEpoch()) > 48*60*60))
 				break;
-			$cd = date_str($co->GetCommitterEpoch());
 			$commitline = array();
-			$commitline["cdmday"] = $cd['mday'];
-			$commitline["cdmonth"] = $cd['month'];
-			$commitline["cdhour"] = $cd['hour'];
-			$commitline["cdminute"] = $cd['minute'];
+			$commitline["committerepoch"] = $co->GetCommitterEpoch();
 			$commitline["title"] = $co->GetTitle();
 			$commitline["author"] = $co->GetAuthor();
-			$commitline["cdrfc2822"] = $cd['rfc2822'];
 			$commitline["commit"] = $commit;
 			$commitline["comment"] = $co->GetComment();
 

--- a/include/controller/Controller_Tag.class.php
+++ b/include/controller/Controller_Tag.class.php
@@ -9,8 +9,6 @@
  * @package GitPHP
  * @subpackage Controller
  */
-
-require_once(GITPHP_INCLUDEDIR . 'util.date_str.php');
 
 /**
  * Tag controller class
@@ -93,11 +91,6 @@
 		$tag = new GitPHP_Tag($this->project, $this->params['hash']);
 
 		$this->tpl->assign("tag", $tag);
-		$tagger = $tag->GetTagger();
-		if (!empty($tagger)) {
-			$ad = date_str($tag->GetTaggerEpoch(), $tag->GetTaggerTimezone());
-			$this->tpl->assign("datedata",$ad);
-		}
 	}
 
 }

--- a/include/git/Commit.class.php
+++ b/include/git/Commit.class.php
@@ -237,6 +237,25 @@
 	}
 
 	/**
+	 * GetAuthorLocalEpoch
+	 *
+	 * Gets the author's local epoch
+	 *
+	 * @access public
+	 * @return string author local epoch
+	 */
+	public function GetAuthorLocalEpoch()
+	{
+		$epoch = $this->GetAuthorEpoch();
+		$tz = $this->GetAuthorTimezone();
+		if (preg_match('/^([+\-][0-9][0-9])([0-9][0-9])$/', $tz, $regs)) {
+			$local = $epoch + ((((int)$regs[1]) + ($regs[2]/60)) * 3600);
+			return $local;
+		}
+		return $epoch;
+	}
+
+	/**
 	 * GetAuthorTimezone
 	 *
 	 * Gets the author's timezone
@@ -287,10 +306,10 @@
 	/**
 	 * GetCommitterEpoch
 	 *
-	 * Gets the author's epoch
-	 *
-	 * @access public
-	 * @return string author epoch
+	 * Gets the committer's epoch
+	 *
+	 * @access public
+	 * @return string committer epoch
 	 */
 	public function GetCommitterEpoch()
 	{
@@ -298,6 +317,25 @@
 			$this->ReadData();
 
 		return $this->committerEpoch;
+	}
+
+	/**
+	 * GetCommitterLocalEpoch
+	 *
+	 * Gets the committer's local epoch
+	 *
+	 * @access public
+	 * @return string committer local epoch
+	 */
+	public function GetCommitterLocalEpoch()
+	{
+		$epoch = $this->GetCommitterEpoch();
+		$tz = $this->GetCommitterTimezone();
+		if (preg_match('/^([+\-][0-9][0-9])([0-9][0-9])$/', $tz, $regs)) {
+			$local = $epoch + ((((int)$regs[1]) + ($regs[2]/60)) * 3600);
+			return $local;
+		}
+		return $epoch;
 	}
 
 	/**

--- a/include/git/Tag.class.php
+++ b/include/git/Tag.class.php
@@ -164,6 +164,25 @@
 			$this->ReadData();
 
 		return $this->taggerEpoch;
+	}
+
+	/**
+	 * GetTaggerLocalEpoch
+	 *
+	 * Gets the tagger local epoch
+	 *
+	 * @access public
+	 * @return string tagger local epoch
+	 */
+	public function GetTaggerLocalEpoch()
+	{
+		$epoch = $this->GetTaggerEpoch();
+		$tz = $this->GetTaggerTimezone();
+		if (preg_match('/^([+\-][0-9][0-9])([0-9][0-9])$/', $tz, $regs)) {
+			$local = $epoch + ((((int)$regs[1]) + ($regs[2]/60)) * 3600);
+			return $local;
+		}
+		return $epoch;
 	}
 
 	/**

--- a/include/gitutil.git_parse_blame.php
+++ b/include/gitutil.git_parse_blame.php
@@ -8,7 +8,6 @@
  */
 
 require_once('gitutil.git_read_blame.php');
-require_once('util.date_str.php');
 
 function git_parse_blame($file, $rev = null)
 {
@@ -43,14 +42,14 @@
 			$commitgroup['commitdata']['author'] = $regs[1];
 			$commitcache[$commitgroup['commit']]['author'] = $regs[1];
 		} else if (preg_match("/^author-mail (.*)$/",$line,$regs)) {
-			$commitgroup['commitdata']['author-mail'] = $regs[1];
-			$commitcache[$commitgroup['commit']]['author-mail'] = $regs[1];
+			$commitgroup['commitdata']['authormail'] = $regs[1];
+			$commitcache[$commitgroup['commit']]['authormail'] = $regs[1];
 		} else if (preg_match("/^author-time (.*)$/",$line,$regs)) {
-			$commitgroup['commitdata']['author-time'] = $regs[1];
-			$commitcache[$commitgroup['commit']]['author-time'] = $regs[1];
+			$commitgroup['commitdata']['authortime'] = $regs[1];
+			$commitcache[$commitgroup['commit']]['authortime'] = $regs[1];
 		} else if (preg_match("/^author-tz (.*)$/",$line,$regs)) {
-			$commitgroup['commitdata']['author-tz'] = $regs[1];
-			$commitcache[$commitgroup['commit']]['author-tz'] = $regs[1];
+			$commitgroup['commitdata']['authortz'] = $regs[1];
+			$commitcache[$commitgroup['commit']]['authortz'] = $regs[1];
 		} else if (preg_match("/^summary (.*)$/",$line,$regs)) {
 			$commitgroup['commitdata']['summary'] = $regs[1];
 			$commitcache[$commitgroup['commit']]['summary'] = $regs[1];
@@ -62,26 +61,6 @@
 	if ($commitgroup)
 		$blamedata[] = $commitgroup;
 
-	$len = count($blamedata);
-	for ($i = 0; $i < $len; $i++) {
-		if (isset($blamedata[$i]['commitdata']['author-time'])) {
-			$authortime = $blamedata[$i]['commitdata']['author-time'];
-			$authortz = "-0000";
-			if (isset($blamedata[$i]['commitdata']['author-tz']))
-				$authortz = $blamedata[$i]['commitdata']['author-tz'];
-			$date = date_str($authortime, $authortz);
-			$blamedata[$i]['commitdata']['authordate'] = $date['ymd-time'];
-		}
-		if (isset($blamedata[$i]['commitdata']['committer-time'])) {
-			$committertime = $blamedata[$i]['commitdata']['committer-time'];
-			$committertz = "-0000";
-			if (isset($blamedata[$i]['commitdata']['committer-tz']))
-				$committertz = $blamedata[$i]['commitdata']['committer-tz'];
-			$date = date_str($committertime, $committertz);
-			$blamedata[$i]['commitdata']['committerdate'] = $date['ymd-time'];
-		}
-	}
-
 	return $blamedata;
 }
 

--- a/include/util.date_str.php
+++ /dev/null
@@ -1,32 +1,1 @@
-<?php
-/*
- *  util.date_str.php
- *  gitphp: A PHP git repository browser
- *  Component: Utility - Date string
- *
- *  Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
- */
 
-function date_str($epoch,$tz = "-0000")
-{
-	date_default_timezone_set('UTC');
-	$date = array();
-	$date['hour'] = date("H",$epoch);
-	$date['minute'] = date("i",$epoch);
-	$date['mday'] = date("d",$epoch);
-	$date['day'] = date("D",$epoch);
-	$date['month'] = date("M",$epoch);
-	$date['rfc2822'] = date("r",$epoch);
-	$date['mday-time'] = date("d M H:i",$epoch);
-	$date['ymd-time'] = date("Y-m-d H:i",$epoch);
-	if (preg_match("/^([+\-][0-9][0-9])([0-9][0-9])$/",$tz,$regs)) {
-		$local = $epoch + ((((int)$regs[1]) + ($regs[2]/60)) * 3600);
-		$date['hour_local'] = date("H",$local);
-		$date['minute_local'] = date("i",$local);
-		$date['tz_local'] = $tz;
-	}
-	return $date;
-}
-
-?>
-

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -34,6 +34,8 @@
 
 require_once(GITPHP_INCLUDEDIR . 'MessageException.class.php');
 require_once(GITPHP_CONTROLLERDIR . 'Controller.class.php');
+
+date_default_timezone_set('UTC');
 
 try {
 

--- a/templates/blame.tpl
+++ b/templates/blame.tpl
@@ -64,9 +64,9 @@
 			<td class="date">
 			{if $smarty.foreach.linegroup.first}
 			{if $blameitem.commit}
-			<a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$blameitem.commit}" title="{$blameitem.commitdata.summary}">{$blameitem.commitdata.authordate}</a>
+			<a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$blameitem.commit}" title="{$blameitem.commitdata.summary}">{$blameitem.commitdata.authortime|date_format:"%F %X"}</a>
 			{else}
-			{$blameitem.commitdata.authordate}
+			{$blameitem.commitdata.authortime|date_format:"%F %X"}
 			{/if}
 			{/if}
 			</td>

--- a/templates/commit.tpl
+++ b/templates/commit.tpl
@@ -48,7 +48,13 @@
      </tr>
      <tr>
        <td></td>
-       <td> {$adrfc2822} ({if $adhourlocal < 6}<span class="latenight">{/if}{$adhourlocal}:{$adminutelocal}{if $adhourlocal < 6}</span>{/if} {$adtzlocal})</td>
+       <td> {$commit->GetAuthorEpoch()|date_format:"%a, %d %b %Y %H:%M:%S %z"} 
+       {assign var=hourlocal value=$commit->GetAuthorLocalEpoch()|date_format:"%H"}
+       {if $hourlocal < 6}
+       (<span class="latenight">{$commit->GetAuthorLocalEpoch()|date_format:"%R"}</span> {$commit->GetAuthorTimezone()})</td>
+       {else}
+       ({$commit->GetAuthorLocalEpoch()|date_format:"%R"} {$commit->GetAuthorTimezone()})</td>
+       {/if}
      </tr>
      <tr>
        <td>committer</td>
@@ -56,7 +62,7 @@
      </tr>
      <tr>
        <td></td>
-       <td> {$cdrfc2822} ({$cdhourlocal}:{$cdminutelocal} {$cdtzlocal})</td>
+       <td> {$commit->GetCommitterEpoch()|date_format:"%a, %d %b %Y %H:%M:%S %z"} ({$commit->GetCommitterLocalEpoch()|date_format:"%R"} {$commit->GetCommitterTimezone()})</td>
      </tr>
      <tr>
        <td>commit</td>

--- a/templates/diff_plaintext.tpl
+++ b/templates/diff_plaintext.tpl
@@ -6,7 +6,7 @@
  *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
  *}
 From: {$from}
-Date: {$date}
+Date: {$date|date_format:"%a, %d %b %Y %H:%M:%S %z"}
 Subject: {$subject}
 {if $tagname}
 X-Git-Tag: {$tagname}

--- a/templates/log.tpl
+++ b/templates/log.tpl
@@ -54,7 +54,7 @@
        <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$commitlines[log].commit}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$commitlines[log].commit}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$commitlines[log].commit}&hb={$commitlines[log].commit}">tree</a>
        <br />
      </div>
-     <i>{$commitlines[log].authorname} [{$commitlines[log].rfc2822}]</i><br />
+     <em>{$commitlines[log].authorname} [{$commitlines[log].authorepoch|date_format:"%a, %d %b %Y %H:%M:%S %z"}]</em><br />
    </div>
    <div class="log_body">
      {foreach from=$commitlines[log].comment item=line}

--- a/templates/project.tpl
+++ b/templates/project.tpl
@@ -18,7 +18,7 @@
  <table cellspacing="0">
    <tr><td>description</td><td>{$description}</td></tr>
    <tr><td>owner</td><td>{$owner}</td></tr>
-   <tr><td>last change</td><td>{$lastchange}</td></tr>
+   <tr><td>last change</td><td>{$lastchange|date_format:"%a, %d %b %Y %H:%M:%S %z"}</td></tr>
    {if $cloneurl}
      <tr><td>clone url</td><td>{$cloneurl}</td></tr>
    {/if}

--- a/templates/rss.tpl
+++ b/templates/rss.tpl
@@ -15,9 +15,9 @@
 
     {section name=rssitem loop=$commitlines}
       <item>
-        <title>{$commitlines[rssitem].cdmday} {$commitlines[rssitem].cdmonth} {$commitlines[rssitem].cdhour}:{$commitlines[rssitem].cdminute} - {$commitlines[rssitem].title|escape:'html'}</title>
+        <title>{$commitlines[rssitem].committerepoch|date_format:"%d %b %R"} - {$commitlines[rssitem].title|escape:'html'}</title>
         <author>{$commitlines[rssitem].author|escape:'html'}</author>
-        <pubDate>{$commitlines[rssitem].cdrfc2822}</pubDate>
+        <pubDate>{$commitlines[rssitem].committerepoch|date_format:"%a, %d %b %Y %H:%M:%S %z"}</pubDate>
         <guid isPermaLink="true">{$self}?p={$project}&amp;a=commit&amp;h={$commitlines[rssitem].commit}</guid>
         <link>{$self}?p={$project}&amp;a=commit&amp;h={$commitlines[rssitem].commit}</link>
         <description>{$commitlines[rssitem].title|escape:'html'}</description>

--- a/templates/tag.tpl
+++ b/templates/tag.tpl
@@ -32,7 +32,13 @@
        </tr>
        <tr>
          <td></td>
-	 <td> {$datedata.rfc2822} ({if $datedata.hour_local < 6}<span class="latenight">{/if}{$datedata.hour_local}:{$datedata.minute_local}{if $datedata.hour_local < 6}</span>{/if} {$datedata.tz_local})
+	 <td> {$tag->GetTaggerEpoch()|date_format:"%a, %d %b %Y %H:%M:%S %z"} 
+	 {assign var=hourlocal value=$tag->GetTaggerLocalEpoch()|date_format:"%H"}
+	 {if $hourlocal < 6}
+	 (<span class="latenight">{$tag->GetTaggerLocalEpoch()|date_format:"%R"}</span> {$tag->GetTaggerTimezone()})
+	 {else}
+	 ({$tag->GetTaggerLocalEpoch()|date_format:"%R"} {$tag->GetTaggerTimezone()})
+	 {/if}
          </td>
        </tr>
      {/if}

comments