Permalink
Browse files

BackwardsCompatibilityBreak - Removed fDate::getSecondsDifference(), …

…fTime::getSecondsDifference(), fTimestamp::getSecondsDifference(), fTimestamp::getSeconds(). Added fDate::eq(), fDate::gt(), fDate::gte(), fDate::lt(), fDate::lte(), fTime::eq(), fTime::gt(), fTime::gte(), fTime::lt(), fTime::lte(), fTimestamp::eq(), fTimestamp::gt(), fTimestamp::gte(), fTimestamp::lt(), fTimestamp::lte().
  • Loading branch information...
wbond committed Mar 6, 2009
1 parent 2ac5afe commit 322743e071d127705acbbff0e94b4d22c01556ca
Showing with 177 additions and 31 deletions.
  1. +59 −6 classes/fDate.php
  2. +59 −6 classes/fTime.php
  3. +59 −19 classes/fTimestamp.php
View
@@ -9,7 +9,8 @@
* @package Flourish
* @link http://flourishlib.com/fDate
*
* @version 1.0.0b5
* @version 1.0.0b6
* @changes 1.0.0b6 Backwards compatibility break - Removed ::getSecondsDifference(), added ::eq(), ::gt(), ::gte(), ::lt(), ::lte() [wb, 2009-03-05]
* @changes 1.0.0b5 Updated for new fCore API [wb, 2009-02-16]
* @changes 1.0.0b4 Fixed ::__construct() to properly handle the 5.0 to 5.1 change in strtotime() [wb, 2009-01-21]
* @changes 1.0.0b3 Added support for CURRENT_TIMESTAMP and CURRENT_DATE SQL keywords [wb, 2009-01-11]
@@ -134,6 +135,19 @@ public function adjust($adjustment)
}
/**
* If this date is equal to the date passed
*
* @param fDate|object|string|integer $other_date The date to compare with, `NULL` is interpreted as today
* @return boolean If this date is equal to the one passed
*/
public function eq($other_date=NULL)
{
$other_date = new fDate($other_date);
return $this->date == $other_date->date;
}
/**
* Formats the date
*
@@ -256,15 +270,54 @@ public function getFuzzyDifference($other_date=NULL)
/**
* Returns the difference between the two dates in seconds
* If this date is greater than the date passed
*
* @param fDate|object|string|integer $other_date The date to compare with, `NULL` is interpreted as today
* @return boolean If this date is greater than the one passed
*/
public function gt($other_date=NULL)
{
$other_date = new fDate($other_date);
return $this->date > $other_date->date;
}
/**
* If this date is greater than or equal to the date passed
*
* @param fDate|object|string|integer $other_date The date to compare with, `NULL` is interpreted as today
* @return boolean If this date is greater than or equal to the one passed
*/
public function gte($other_date=NULL)
{
$other_date = new fDate($other_date);
return $this->date >= $other_date->date;
}
/**
* If this date is less than the date passed
*
* @param fDate|object|string|integer $other_date The date to compare with, `NULL` is interpreted as today
* @return boolean If this date is less than the one passed
*/
public function lt($other_date=NULL)
{
$other_date = new fDate($other_date);
return $this->date < $other_date->date;
}
/**
* If this date is less than or equal to the date passed
*
* @param fDate|object|string|integer $other_date The date to calculate the difference with, `NULL` is interpreted as today
* @return integer The difference between the two dates in seconds, positive if `$other_date` is before this date or negative if after
* @param fDate|object|string|integer $other_date The date to compare with, `NULL` is interpreted as today
* @return boolean If this date is less than or equal to the one passed
*/
public function getSecondsDifference($other_date=NULL)
public function lte($other_date=NULL)
{
$other_date = new fDate($other_date);
return $this->date - $other_date->date;
return $this->date <= $other_date->date;
}
View
@@ -9,7 +9,8 @@
* @package Flourish
* @link http://flourishlib.com/fTime
*
* @version 1.0.0b6
* @version 1.0.0b7
* @changes 1.0.0b7 Backwards compatibility break - Removed ::getSecondsDifference(), added ::eq(), ::gt(), ::gte(), ::lt(), ::lte() [wb, 2009-03-05]
* @changes 1.0.0b6 Fixed an outdated fCore method call [wb, 2009-02-23]
* @changes 1.0.0b5 Updated for new fCore API [wb, 2009-02-16]
* @changes 1.0.0b4 Fixed ::__construct() to properly handle the 5.0 to 5.1 change in strtotime() [wb, 2009-01-21]
@@ -135,6 +136,19 @@ public function adjust($adjustment)
}
/**
* If this time is equal to the time passed
*
* @param fTime|object|string|integer $other_time The time to compare with, `NULL` is interpreted as today
* @return boolean If this time is equal to the one passed
*/
public function eq($other_time=NULL)
{
$other_time = new fTime($other_time);
return $this->time == $other_time->time;
}
/**
* Formats the time
*
@@ -249,15 +263,54 @@ public function getFuzzyDifference($other_time=NULL)
/**
* Returns the difference between the two times in seconds
* If this time is greater than the time passed
*
* @param fTime|object|string|integer $other_time The time to compare with, `NULL` is interpreted as now
* @return boolean If this time is greater than the one passed
*/
public function gt($other_time=NULL)
{
$other_time = new fTime($other_time);
return $this->time > $other_time->time;
}
/**
* If this time is greater than or equal to the time passed
*
* @param fTime|object|string|integer $other_time The time to compare with, `NULL` is interpreted as now
* @return boolean If this time is greater than or equal to the one passed
*/
public function gte($other_time=NULL)
{
$other_time = new fTime($other_time);
return $this->time >= $other_time->time;
}
/**
* If this time is less than the time passed
*
* @param fTime|object|string|integer $other_time The time to compare with, `NULL` is interpreted as today
* @return boolean If this time is less than the one passed
*/
public function lt($other_time=NULL)
{
$other_time = new fTime($other_time);
return $this->time < $other_time->time;
}
/**
* If this time is less than or equal to the time passed
*
* @param fTime|object|string|integer $other_time The time to calculate the difference with, `NULL` is interpreted as now
* @return integer The difference between the two times in seconds, positive if $other_time is before this time or negative if after
* @param fTime|object|string|integer $other_time The time to compare with, `NULL` is interpreted as today
* @return boolean If this time is less than or equal to the one passed
*/
public function getSecondsDifference($other_time=NULL)
public function lte($other_time=NULL)
{
$other_time = new fTime($other_time);
return $this->time - $other_time->time;
return $this->time <= $other_time->time;
}
View
@@ -9,7 +9,8 @@
* @package Flourish
* @link http://flourishlib.com/fTimestamp
*
* @version 1.0.0b4
* @version 1.0.0b5
* @changes 1.0.0b5 Backwards compatibility break - Removed ::getSecondsDifference() and ::getSeconds(), added ::eq(), ::gt(), ::gte(), ::lt(), ::lte() [wb, 2009-03-05]
* @changes 1.0.0b4 Updated for new fCore API [wb, 2009-02-16]
* @changes 1.0.0b3 Removed a useless double check of the strtotime() return value in ::__construct() [wb, 2009-01-21]
* @changes 1.0.0b2 Added support for CURRENT_TIMESTAMP, CURRENT_DATE and CURRENT_TIME SQL keywords [wb, 2009-01-11]
@@ -23,7 +24,6 @@ class fTimestamp
const defineFormat = 'fTimestamp::defineFormat';
const fixISOWeek = 'fTimestamp::fixISOWeek';
const getDefaultTimezone = 'fTimestamp::getDefaultTimezone';
const getSeconds = 'fTimestamp::getSeconds';
const isValidTimezone = 'fTimestamp::isValidTimezone';
const registerFormatCallback = 'fTimestamp::registerFormatCallback';
const reset = 'fTimestamp::reset';
@@ -156,18 +156,6 @@ static public function getDefaultTimezone()
}
/**
* Returns the number of seconds in a given timespan (e.g. `'30 minutes'`, `'1 hour'`, `'5 days'`, etc). Useful for comparing with `getSecondsDifference()` methods in fDate, fTime and fTimestamp.
*
* @param string $timespan The timespan to calculate the number of seconds in
* @return integer The number of seconds in the timestamp specified
*/
static public function getSeconds($timespan)
{
return strtotime($timespan) - time();
}
/**
* Checks to see if a timezone is valid
*
@@ -825,6 +813,19 @@ public function adjust($adjustment)
}
/**
* If this timestamp is equal to the timestamp passed
*
* @param fTimestamp|object|string|integer $other_timestamp The timestamp to compare with, `NULL` is interpreted as today
* @return boolean If this timestamp is equal to the one passed
*/
public function eq($other_timestamp=NULL)
{
$other_timestamp = new fTimestamp($other_timestamp);
return $this->timestamp == $other_timestamp->timestamp;
}
/**
* Formats the date/time
*
@@ -957,15 +958,54 @@ public function getFuzzyDifference($other_timestamp=NULL)
/**
* Returns the difference between the two timestamps in seconds
* If this timestamp is greater than the timestamp passed
*
* @param fTimestamp|object|string|integer $other_timestamp The timestamp to compare with, `NULL` is interpreted as now
* @return boolean If this timestamp is greater than the one passed
*/
public function gt($other_timestamp=NULL)
{
$other_timestamp = new fTimestamp($other_timestamp);
return $this->timestamp > $other_timestamp->timestamp;
}
/**
* If this timestamp is greater than or equal to the timestamp passed
*
* @param fTimestamp|object|string|integer $other_timestamp The timestamp to compare with, `NULL` is interpreted as now
* @return boolean If this timestamp is greater than or equal to the one passed
*/
public function gte($other_timestamp=NULL)
{
$other_timestamp = new fTimestamp($other_timestamp);
return $this->timestamp >= $other_timestamp->timestamp;
}
/**
* If this timestamp is less than the timestamp passed
*
* @param fTimestamp|object|string|integer $other_timestamp The timestamp to compare with, `NULL` is interpreted as today
* @return boolean If this timestamp is less than the one passed
*/
public function lt($other_timestamp=NULL)
{
$other_timestamp = new fTimestamp($other_timestamp);
return $this->timestamp < $other_timestamp->timestamp;
}
/**
* If this timestamp is less than or equal to the timestamp passed
*
* @param fTimestamp|object|string|integer $other_timestamp The timestamp to calculate the difference with, `NULL` is interpreted as now
* @return integer The difference between the two timestamps in seconds, positive if the other timestamp is before this time or negative if after
* @param fTimestamp|object|string|integer $other_timestamp The timestamp to compare with, `NULL` is interpreted as today
* @return boolean If this timestamp is less than or equal to the one passed
*/
public function getSecondsDifference($other_timestamp=NULL)
public function lte($other_timestamp=NULL)
{
$other_timestamp = new fTimestamp($other_timestamp);
return $this->timestamp - $other_timestamp->timestamp;
return $this->timestamp <= $other_timestamp->timestamp;
}

0 comments on commit 322743e

Please sign in to comment.