예제 #1
0
 public function testGetDayStartEndFromStringToFormat()
 {
     $time = '21-Feb-15 18:27:52';
     $format = 'Y-m-d H:i:s';
     $expected_start = '2015-02-21 00:00:00';
     $expected_end = '2015-02-21 23:59:59';
     $this->assertEquals($this->util->getDayStart($time, $format), $expected_start);
     $this->assertEquals($this->util->getDayEnd($time, $format), $expected_end);
 }
예제 #2
0
namespace Events\UI;

use Events\API\Calendar;
use Events\API\Util;
use Events\API\PAM;
$is_logged_in = elgg_is_logged_in();
$guid = get_input('guid');
$consumer = get_input('consumer');
if (!$is_logged_in) {
    $token = get_input('token');
    $user_guid = get_input('uid');
    try {
        PAM::authenticate();
    } catch (Exception $ex) {
        register_error($ex->getMessage());
        forward('', '403');
    }
}
$entity = get_entity($guid);
if (!$entity instanceof Calendar) {
    forward('', '404');
}
$start = (int) get_input('start', time());
$end = (int) get_input('end', strtotime('+1 month', $start));
$start = (int) Util::getDayStart($start);
$end = (int) Util::getDayEnd($end);
$events = $entity->getAllEventInstances($start, $end, true, $consumer);
echo json_encode($events);
if (!$is_logged_in) {
    logout();
}
예제 #3
0
 /**
  * Calculates a timestamp by extracting time from $ts_time and adding it to the day start on $ts_day
  *
  * @param mixed $ts_time Date/time string containing time information
  * @param mixed $ts_day  Date/time string containing day information
  * @return int
  */
 public static function getTimeOfDay($ts_time = 0, $ts_day = null, $format = 'U', $tz = null)
 {
     if (!Util::isValidTimezone($tz)) {
         $tz = Util::getClientTimezone();
     }
     $time = Util::getTime($ts_time, 'U', $tz);
     $day_start = Util::getDayStart($ts_day, 'U', $tz);
     $dt = new DateTime(null, new DateTimeZone($tz));
     return $dt->setTimestamp($time + $day_start)->format($format);
 }