[Piwik-svn] r540 - in trunk/modules: . Period

svnmaster at piwik.org svnmaster at piwik.org
Mon Jun 30 00:44:15 CEST 2008


Author: matt
Date: 2008-06-30 00:44:13 +0200 (Mon, 30 Jun 2008)
New Revision: 540

Modified:
   trunk/modules/Date.php
   trunk/modules/Period.php
   trunk/modules/Period/Range.php
Log:
- fix #245 last1 does not work with month and year

Modified: trunk/modules/Date.php
===================================================================
--- trunk/modules/Date.php	2008-06-29 22:05:21 UTC (rev 539)
+++ trunk/modules/Date.php	2008-06-29 22:44:13 UTC (rev 540)
@@ -177,6 +177,10 @@
      */
     public function subDay( $n )
     {
+    	if($n === 0) 
+    	{
+    		return clone $this;
+    	}
     	$ts = strtotime("-$n day", $this->getTimestamp());
 		return new Piwik_Date( $ts );
     }
@@ -190,6 +194,10 @@
      */
     public function subMonth( $n )
     {
+    	if($n === 0) 
+    	{
+    		return clone $this;
+    	}
 		$ts = $this->getTimestamp();
 		$result = mktime( 
 						date('H', $ts),

Modified: trunk/modules/Period/Range.php
===================================================================
--- trunk/modules/Period/Range.php	2008-06-29 22:05:21 UTC (rev 539)
+++ trunk/modules/Period/Range.php	2008-06-29 22:44:13 UTC (rev 540)
@@ -19,6 +19,12 @@
 		return $out;
 	}
 
+	/**
+	 *
+	 * @param Piwik_Date $date
+	 * @param int $n
+	 * @return Piwik_Date
+	 */
 	protected function removePeriod( $date, $n )
 	{
 		switch($this->strPeriod)
@@ -68,6 +74,7 @@
 		}
 		return $lastN;
 	}
+	
 	public function setDefaultEndDate( Piwik_Date $oDate)
 	{
 		$this->defaultEndDate = $oDate;
@@ -129,7 +136,7 @@
 		
 		$arrayPeriods= array();
 		$arrayPeriods[] = $endSubperiod;
-		while($endDate->isLater($startDate))
+		while($endDate->isLater($startDate) )
 		{
 			$endDate = $this->removePeriod($endDate, 1);
 			$subPeriod = Piwik_Period::factory($this->strPeriod, $endDate);

Modified: trunk/modules/Period.php
===================================================================
--- trunk/modules/Period.php	2008-06-29 22:05:21 UTC (rev 539)
+++ trunk/modules/Period.php	2008-06-29 22:44:13 UTC (rev 540)
@@ -34,7 +34,7 @@
 	
 	protected static $unknowPeriodException = "The period '%s' is not supported. Try 'day' or 'week' or 'month' or 'year'";
 	
-	protected function __construct( $date )
+	public function __construct( $date )
 	{	
 		$this->checkInputDate( $date );
 		$this->date = clone $date;



More information about the Piwik-svn mailing list