/**
  * @since 4.6.x
  */
 public function test_create_new_blank_datetime()
 {
     //if timezone is empty string then the setUp didn't work correctly.  For the purpose of this test
     //we want a high positive timezone, so let's force that if necessary
     if (get_option('timezone_string') != 'Australia/Sydney') {
         update_option('timezone_string', 'Australia/Sydney');
         EEM_Datetime::reset();
         EEM_Datetime::instance();
     }
     EE_Registry::instance()->load_helper('DTT_Helper');
     //make sure now is in the timezone we want to test with.
     $now = new Datetime('@' . (time() + DAY_IN_SECONDS * 30));
     $now->setTimeZone(new DateTimeZone(EEH_DTT_Helper::get_timezone()));
     $now->setTime('8', '0', '0');
     $now->setTimeZone(new DateTimeZone('America/Toronto'));
     //get the default datetime
     $default_date = EEM_Datetime::instance()->create_new_blank_datetime();
     $default_date = reset($default_date);
     //assert instance
     $this->assertInstanceOf('EE_Datetime', $default_date);
     //set its timezone to match our expected timezone
     $default_date->set_timezone('America/Toronto');
     $actual = $default_date->get_DateTime_object('DTT_EVT_start');
     $this->assertInstanceOf('DateTime', $actual);
     //assert timezones are the same
     $this->assertEquals($now->getTimezone(), $actual->getTimeZone());
     //assert that we have the correct values on the date... we'll do each part separately to verify.
     $this->assertEquals($now->format('Y'), $actual->format('Y'));
     $this->assertEquals($now->format('m'), $actual->format('m'));
     $this->assertEquals($now->format('d'), $actual->format('d'));
     $this->assertEquals($now->format('H'), $actual->format('H'));
     $this->assertEquals($now->format('i'), $actual->format('i'));
 }
示例#2
0
 /**
  * @param array $events
  *
  * @return Twig view in ics format
  */
 private function writeCalendar(array $events)
 {
     $date = new \Datetime();
     $tz = $date->getTimezone();
     return $this->container->get('templating')->render('ClarolineAgendaBundle:Tool:exportIcsCalendar.ics.twig', ['tzName' => $tz->getName(), 'events' => $events]);
 }
示例#3
0
 /**
  * This function wraps around the phprojekt setting for the user timezone
  * to return a DateTimeZone object.
  *
  * @return DateTimeZone The timezone of the user.
  */
 public static function getUserDateTimeZone()
 {
     $tz = Phprojekt_Auth_Proxy::getEffectiveUser()->getSetting('timezone', '0');
     $tz = explode('_', $tz);
     $hours = (int) $tz[0];
     if ($hours >= 0) {
         $hours = '+' . $hours;
     }
     $minutes = '00';
     if (array_key_exists(1, $tz)) {
         // We don't need the minus sign
         $minutes = abs($tz[1]);
     }
     $datetime = new Datetime($hours . ':' . $minutes);
     return $datetime->getTimezone();
 }