for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace JhFlexiTime\Controller;
use Zend\Validator\Date as DateValidator;
use JhFlexiTime\DateTime\DateTime;
/**
* Class GetSetDateTrait
* @author Aydin Hassan <[email protected]>
*/
trait GetSetDateTrait
{
* @var DateTime
protected $date;
* @param string $month
* @param string $year
* @return DateTime
public function getDate($month = null, $year = null)
if (!$this->date) {
$validator = new DateValidator(['format' => 'M Y']);
if ($validator->isValid(sprintf("%s %s", $month, $year))) {
$period = new DateTime(sprintf('last day of %s %s 23:59:59', $month, $year));
} else {
$period = new DateTime;
}
$this->date = $period;
return $this->date;
* @param DateTime $date
public function setDate(DateTime $date)
$this->date = $date;