Esempio n. 1
0
 /**
  * Universal setter for dates
  *
  * @param     DateTime|string $date         The date to set, either as string or DateTime instance
  * @param     string          $property     The name of the property to set
  * @param     bool            $end_of_day   Whether the time should be shifted to the end of the day
  */
 protected function setDateUniversal($date, $property, $end_of_day = false)
 {
     if (is_string($date) and (preg_match(Dates::STD_DATE_FORMAT_REGEX, $date) or preg_match(Dates::STD_DATE_FORMAT_REGEX . ' ' . Dates::STD_TIME_FORMAT_REGEX, $date))) {
         $date = new DateTime($date);
     }
     if (!$date instanceof DateTime) {
         add_notice(sprintf('Argument one for %s has to be of type string or DateTime, %s given', __CLASS__ . '::' . __METHOD__, gettype($date)));
     }
     $date = Dates::applyTimeZone($date);
     if ($end_of_day === true) {
         $date->setTime(23, 59, 59);
     }
     $this->{$property} = Dates::applyTimeZone($date);
 }
Esempio n. 2
0
 public function testApplyTimezone()
 {
     $date = new DateTime('now', new DateTimeZone('America/Anchorage'));
     Dates::applyTimeZone($date);
     $this->assertEquals(Dates::getTimezone(), $date->getTimezone());
 }