Skip to content
Permalink
Browse files

automatically set refreshTimestamp on set

If a user sets the timestamp, but refreshTimestamp is truthy, the set
value will effectivley be ignored
  • Loading branch information...
AD7six committed Nov 29, 2013
1 parent 5272919 commit 75342bb8ad90d1842811485020e96650ecb62d68
@@ -108,13 +108,18 @@ public function implementedEvents() {
* Get or set the timestamp to be used
*
* Set the timestamp to the given DateTime object, or if not passed a new DateTime object
* If an explicit date time is passed, the config option `refreshTimestamp` is
* automatically set to false.
*
* @param \DateTime $ts
* @param bool $refreshTimestamp
* @return \DateTime
*/
public function timestamp(\DateTime $ts = null, $refreshTimestamp = false) {
if ($ts) {
if ($this->_config['refreshTimestamp']) {
$this->_config['refreshTimestamp'] = false;
}
$this->_ts = $ts;
} elseif ($this->_ts === null || $refreshTimestamp) {
$this->_ts = new \DateTime();
@@ -83,7 +83,7 @@ public function testImplementedEventsCustom() {
*/
public function testCreatedAbsent() {
$table = $this->getMock('Cake\ORM\Table');
$this->Behavior = new TimestampBehavior($table, ['refreshTimestamp' => false]);
$this->Behavior = new TimestampBehavior($table);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);
@@ -102,7 +102,7 @@ public function testCreatedAbsent() {
*/
public function testCreatedPresent() {
$table = $this->getMock('Cake\ORM\Table');
$this->Behavior = new TimestampBehavior($table, ['refreshTimestamp' => false]);
$this->Behavior = new TimestampBehavior($table);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);
@@ -122,7 +122,7 @@ public function testCreatedPresent() {
*/
public function testCreatedNotNew() {
$table = $this->getMock('Cake\ORM\Table');
$this->Behavior = new TimestampBehavior($table, ['refreshTimestamp' => false]);
$this->Behavior = new TimestampBehavior($table);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);
@@ -142,7 +142,7 @@ public function testCreatedNotNew() {
*/
public function testModifiedAbsent() {
$table = $this->getMock('Cake\ORM\Table');
$this->Behavior = new TimestampBehavior($table, ['refreshTimestamp' => false]);
$this->Behavior = new TimestampBehavior($table);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);
@@ -162,7 +162,7 @@ public function testModifiedAbsent() {
*/
public function testModifiedPresent() {
$table = $this->getMock('Cake\ORM\Table');
$this->Behavior = new TimestampBehavior($table, ['refreshTimestamp' => false]);
$this->Behavior = new TimestampBehavior($table);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);
@@ -283,7 +283,7 @@ public function testSetTimestampExplicit() {
*/
public function testTouch() {
$table = $this->getMock('Cake\ORM\Table');
$this->Behavior = new TimestampBehavior($table, ['refreshTimestamp' => false]);
$this->Behavior = new TimestampBehavior($table);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);
@@ -306,7 +306,6 @@ public function testTouch() {
public function testTouchNoop() {
$table = $this->getMock('Cake\ORM\Table');
$config = [
'refreshTimestamp' => false,
'events' => [
'Model.beforeSave' => [
'created' => 'new',
@@ -332,7 +331,7 @@ public function testTouchNoop() {
*/
public function testTouchCustomEvent() {
$table = $this->getMock('Cake\ORM\Table');
$settings = ['events' => ['Something.special' => ['date_specialed' => 'always']], 'refreshTimestamp' => false];
$settings = ['events' => ['Something.special' => ['date_specialed' => 'always']]];
$this->Behavior = new TimestampBehavior($table, $settings);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);

0 comments on commit 75342bb

Please sign in to comment.
You can’t perform that action at this time.