Elgg  Version 6.2
TimeUsing.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Traits;
4 
10 trait TimeUsing {
11 
15  private $time;
16 
25  public function getCurrentTime($modifier = '') {
26  $time = $this->time ?? new \DateTime();
27  $time = clone $time;
28  if ($modifier) {
29  $time->modify($modifier);
30  }
31 
32  return $time;
33  }
34 
42  public function setCurrentTime(?\DateTime $time = null) {
43  $time = $time ?? new \DateTime();
44  $this->time = clone $time;
45  }
46 
54  public function resetCurrentTime(): void {
55  unset($this->time);
56  }
57 }
setCurrentTime(?\DateTime $time=null)
Set the current time.
Definition: TimeUsing.php:42
resetCurrentTime()
Reset the current time Use after the time has been set with setCurrentTime and it no longer needs to ...
Definition: TimeUsing.php:54
getCurrentTime($modifier='')
Get the (cloned) time.
Definition: TimeUsing.php:25
trait TimeUsing
Adds methods for setting the current time (for testing)
Definition: TimeUsing.php:10
if(! $annotation instanceof ElggAnnotation) $time
Definition: time.php:20
Extension of the DateTime class to support formatting a date using the locale.
Definition: DateTime.php:12