Horde_Icalendar::_parseDateTime PHP Метод

_parseDateTime() публичный Метод

Parses a DateTime field and returns a unix timestamp. If the field cannot be parsed then the original text is returned unmodified.
public _parseDateTime ( $text, $tzid = false ) : TODO
$tzid TODO
Результат TODO
    public function _parseDateTime($text, $tzid = false)
    {
        $dateParts = explode('T', $text);
        if (count($dateParts) != 2 && !empty($text)) {
            // Not a datetime field but may be just a date field.
            if (!preg_match('/^(\\d{4})-?(\\d{2})-?(\\d{2})$/', $text)) {
                // Or not
                return $text;
            }
            $dateParts = array($text, '000000');
        }
        if (!($date = $this->_parseDate($dateParts[0])) || !($time = $this->_parseTime($dateParts[1]))) {
            return $text;
        }
        // Get timezone info for date fields from $tzid and container.
        $tzoffset = $time['zone'] == 'Local' && $tzid && $this->_container instanceof Horde_Icalendar ? $this->_parseTZID($date, $time, $tzid) : false;
        if ($time['zone'] == 'UTC' || $tzoffset !== false) {
            $result = @gmmktime($time['hour'], $time['minute'], $time['second'], $date['month'], $date['mday'], $date['year']);
            if ($result !== false && $tzoffset) {
                $result -= $tzoffset;
            }
        } else {
            // We don't know the timezone so assume local timezone.
            $result = @mktime($time['hour'], $time['minute'], $time['second'], $date['month'], $date['mday'], $date['year']);
        }
        return $result !== false ? $result : $text;
    }

Usage Example

Пример #1
0
 /**
  * Test that the attendee status gets transferred.
  */
 public function testAttendeeStatusInvitation()
 {
     $this->markTestIncomplete('Sends mail');
     require_once 'Horde/Icalendar/Vfreebusy.php';
     $GLOBALS['KOLAB_FILTER_TESTING'] = new Horde_Icalendar_Vfreebusy();
     $GLOBALS['KOLAB_FILTER_TESTING']->setAttribute('DTSTART', Horde_Icalendar::_parseDateTime('20080926T000000Z'));
     $GLOBALS['KOLAB_FILTER_TESTING']->setAttribute('DTEND', Horde_Icalendar::_parseDateTime('20081126T000000Z'));
     $params = array('unmodified_content' => true, 'incoming' => true);
     $this->sendFixture(__DIR__ . '/fixtures/attendee_status_invitation.eml', __DIR__ . '/fixtures/null.ret', '', '', '*****@*****.**', '*****@*****.**', 'home.example.org', $params);
     $result = $this->auth->authenticate('wrobel', array('password' => 'none'));
     $this->assertNoError($result);
     $folder = $this->storage->getFolder('INBOX/Kalender');
     $data = $folder->getData();
     $events = $data->getObjects();
     $summaries = array();
     foreach ($events as $event) {
         foreach ($event['attendee'] as $attendee) {
             switch ($attendee['smtp-address']) {
                 case '*****@*****.**':
                     $this->assertEquals('none', $attendee['status']);
                     break;
                 case '*****@*****.**':
                     $this->assertEquals('accepted', $attendee['status']);
                     break;
                 case '*****@*****.**':
                     $this->assertEquals('declined', $attendee['status']);
                     break;
                 case '*****@*****.**':
                     $this->assertEquals('tentative', $attendee['status']);
                     break;
                 case '*****@*****.**':
                     $this->assertEquals('none', $attendee['status']);
                     break;
                 default:
                     $this->fail('Unexpected attendee!');
                     break;
             }
         }
     }
     $result = $data->deleteAll();
     $this->assertNoError($result);
 }