Commit cfb65a97 by Seldaek

* Fixed a bug in {date_format} that prevented anything but unix timestamps to work

git-svn-id: svn://dwoo.org/dwoo/trunk@62 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 187a71c6
......@@ -493,7 +493,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
// strips comments
if(strstr($tpl, $this->ld.'*') !== false)
$tpl = preg_replace('{'.$this->ldr.'\*.*?\*'.$this->rdr.'}s', '', $tpl);
$tpl = preg_replace('/'.$this->ldr.'\*.*?\*'.$this->rdr.'/s', '', $tpl);
// strips php tags if required by the security policy
if($this->securityPolicy !== null)
......
......@@ -24,14 +24,16 @@ function Dwoo_Plugin_date_format(Dwoo $dwoo, $value, $format='%b %e, %Y', $defau
if(!empty($value))
{
// don't convert if it's a valid unix timestamp
if(preg_match('#^\d{10}$#', $value)===false)
if(preg_match('#^\d{10}$#', $value)===0)
$value = strtotime($value);
}
elseif(!empty($default))
{
// don't convert if it's a valid unix timestamp
if(preg_match('#^\d{10}$#', $default)===false)
if(preg_match('#^\d{10}$#', $default)===0)
$value = strtotime($default);
else
$value = $default;
}
else
return '';
......@@ -39,7 +41,7 @@ function Dwoo_Plugin_date_format(Dwoo $dwoo, $value, $format='%b %e, %Y', $defau
// Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin
if(DIRECTORY_SEPARATOR == '\\')
{
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
if(strpos($format, '%e') !== false)
{
......
......@@ -116,7 +116,7 @@ class FuncTests extends PHPUnit_Framework_TestCase
$tpl = new Dwoo_Template_String('{date_format $dwoo.now "%Y%H:%M:%S"}{date_format $foo "%Y%H:%M:%S" "one hour ago"}{date_format ""}');
$tpl->forceCompilation();
$this->assertEquals(strftime("%Y%H:%M:%S", $_SERVER['REQUEST_TIME']).strftime('%Y%H:%M:%S', strtotime("one hour ago")), $this->dwoo->get($tpl, array(), $this->compiler));
$this->assertEquals(strftime("%Y%H:%M:%S", $_SERVER['REQUEST_TIME']).strftime('%Y%H:%M:%S', strtotime("one hour ago")), $this->dwoo->get($tpl, array('foo'=>''), $this->compiler));
}
public function testDefault()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment