public function __set($strName, $mixValue)
 {
     switch ($strName) {
         case 'MaxDate':
         case 'Maximum':
             try {
                 if (is_string($mixValue)) {
                     $mixValue = new QDateTime($mixValue);
                 }
                 parent::__set('MaxDate', QType::Cast($mixValue, QType::DateTime));
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             break;
         case 'MinDate':
         case 'Minimum':
             try {
                 if (is_string($mixValue)) {
                     $mixValue = new QDateTime($mixValue);
                 }
                 parent::__set('MinDate', QType::Cast($mixValue, QType::DateTime));
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             break;
         case 'DateTime':
             try {
                 $this->dttDateTime = QType::Cast($mixValue, QType::DateTime);
                 if ($this->dttDateTime && $this->dttDateTime->IsNull()) {
                     $this->dttDateTime = null;
                     $this->blnModified = true;
                 }
                 if (!$this->dttDateTime || !$this->strDateTimeFormat) {
                     parent::__set('Text', '');
                 } else {
                     parent::__set('Text', $this->dttDateTime->qFormat($this->strDateTimeFormat));
                 }
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             break;
         case 'JqDateFormat':
             try {
                 parent::__set($strName, $mixValue);
                 $this->strDateTimeFormat = QCalendar::qcFrmt($this->JqDateFormat);
                 // trigger an update to reformat the text with the new format
                 $this->DateTime = $this->dttDateTime;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             break;
         case 'DateTimeFormat':
         case 'DateFormat':
             try {
                 $this->strDateTimeFormat = QType::Cast($mixValue, QType::String);
                 parent::__set('JqDateFormat', QCalendar::jqFrmt($this->strDateTimeFormat));
                 // trigger an update to reformat the text with the new format
                 $this->DateTime = $this->dttDateTime;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             break;
         case 'Text':
             parent::__set($strName, $mixValue);
             $this->dttDateTime = new QDateTime($this->strText);
             break;
         default:
             try {
                 parent::__set($strName, $mixValue);
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             break;
     }
 }
		<input type="submit" id="double" name="double" value="Save 2 Objects (same Instance)"/></p>

		<p>Using <strong>$blnForceUpdate</strong> to avoid the <strong>Optimistic Locking Exception</strong><br/>
		<input type="submit" id="double_force" name="double_force" value="Force Update Second Object"/></p>
	</form>
<?php 
// Load the Two Person objects (same instance -- let them both be Person ID #4)
$objPerson1 = PersonWithLock::Load(5);
$objPerson2 = PersonWithLock::Load(5);
// Some RDBMS Vendors' TIMESTAMP is only precise to the second
// Let's force a delay to the next second to ensure timestamp functionality
// Note: on most web applications, because Optimistic Locking are more application user-
// level constraints instead of systematic ones, this delay is inherit with the web
// application paradigm.  The following delay is just to simulate that paradigm.
$dttNow = new QDateTime(QDateTime::Now);
while ($objPerson1->SysTimestamp == $dttNow->qFormat(QDateTime::FormatIso)) {
    $dttNow = new QDateTime(QDateTime::Now);
}
// Make Changes to the Object so that the Save Will Update Something
if ($objPerson1->FirstName == 'Al') {
    $objPerson1->FirstName = 'Alfred';
    $objPerson2->FirstName = 'Al';
} else {
    $objPerson1->FirstName = 'Al';
    $objPerson2->FirstName = 'Alfred';
}
switch (true) {
    case array_key_exists('single', $_POST):
        $objPerson1->Save();
        _p('Person Id #' . $objPerson1->Id . ' saved.  Name is now ' . $objPerson1->FirstName);
        _p('.<br/>', false);
示例#3
0
 public static function NowToString($strFormat = null)
 {
     $dttNow = new QDateTime(QDateTime::Now);
     return $dttNow->qFormat($strFormat);
 }
示例#4
0
 public function testFormat()
 {
     $obj1 = new QDateTime("2002-3-5 13:15");
     $this->assertEqual($obj1->qFormat("M/D/YY h:mm z"), "3/5/02 1:15 pm");
     $this->assertEqual($obj1->qFormat("DDD MMM D YYYY"), "Tue Mar 5 2002");
     $this->assertEqual($obj1->qFormat("One random DDDD in MMMM"), "One random Tuesday in March");
     //  Back compat
     $this->assertEqual($obj1->qFormat("M/D/YY h:mm z"), $obj1->qFormat("M/D/YY h:mm z"));
 }