TDateTimeStamp Class is a wrapper to DateTime: http://php.net/manual/book.datetime.php Prado implemented this class before php started shipping the DateTime extension. This class is deprecated and left here only for compatibility for legacy code. Please note that this class doesn't support automatic conversion from gregorian to julian dates anymore.
Deprecation: since 3.2.1
Since: 3.0.4
Author: Fabio Bas ctrlaltca[AT]gmail[DOT]com
示例#1
0
 function testRandomDates()
 {
     $start = 1960 + rand(0, 10);
     $yrs = 12;
     $i = 365.25 * 86400 * ($start - 1970);
     $offset = 36000 + rand(10000, 60000);
     $max = 365 * $yrs * 86400;
     $lastyear = 0;
     $s = new TDateTimeStamp();
     // we generate a timestamp, convert it to a date, and convert it back to a timestamp
     // and check if the roundtrip broke the original timestamp value.
     //print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: ";
     $fails = 0;
     for ($max += $i; $i < $max; $i += $offset) {
         $ret = $s->formatDate('m,d,Y,H,i,s', $i);
         $arr = explode(',', $ret);
         if ($lastyear != $arr[2]) {
             $lastyear = $arr[2];
         }
         $newi = $s->getTimestamp($arr[3], $arr[4], $arr[5], $arr[0], $arr[1], $arr[2]);
         if ($i != $newi) {
             // This actually can fail if $i is in the middle of a time change due to DST
             $tz = new DateTimeZone(date_default_timezone_get());
             $transitions = $tz->getTransitions($i - 3600, $i + 3600);
             if (count($transitions) == 0) {
                 $fails++;
             }
             //$j = mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]);
             //print "Error at $i, $j, getTimestamp() returned $newi ($ret)\n";
         }
     }
     $this->assertEquals($fails, 0);
 }
示例#2
0
 /**
  * Parse the string according to the pattern.
  * @param string|int date string or integer to parse
  * @return int date time stamp
  * @throws TInvalidDataValueException if date string is malformed.
  */
 public function parse($value, $defaultToCurrentTime = true)
 {
     if (is_int($value) || is_float($value)) {
         return $value;
     } else {
         if (!is_string($value)) {
             throw new TInvalidDataValueException('date_to_parse_must_be_string', $value);
         }
     }
     if (empty($this->pattern)) {
         return time();
     }
     $date = time();
     if ($this->length(trim($value)) < 1) {
         return $defaultToCurrentTime ? $date : null;
     }
     $pattern = $this->pattern;
     $i_val = 0;
     $i_format = 0;
     $pattern_length = $this->length($pattern);
     $c = '';
     $token = '';
     $x = null;
     $y = null;
     if ($defaultToCurrentTime) {
         $year = "{$date['year']}";
         $month = $date['mon'];
         $day = $date['mday'];
     } else {
         $year = null;
         $month = null;
         $day = null;
     }
     while ($i_format < $pattern_length) {
         $c = $this->charAt($pattern, $i_format);
         $token = '';
         while ($this->charEqual($pattern, $i_format, $c) && $i_format < $pattern_length) {
             $token .= $this->charAt($pattern, $i_format++);
         }
         if ($token == 'yyyy' || $token == 'yy' || $token == 'y') {
             if ($token == 'yyyy') {
                 $x = 4;
                 $y = 4;
             }
             if ($token == 'yy') {
                 $x = 2;
                 $y = 2;
             }
             if ($token == 'y') {
                 $x = 2;
                 $y = 4;
             }
             $year = $this->getInteger($value, $i_val, $x, $y);
             if ($year === null) {
                 return null;
             }
             //throw new TInvalidDataValueException('Invalid year', $value);
             $i_val += strlen($year);
             if (strlen($year) == 2) {
                 $iYear = (int) $year;
                 if ($iYear > 70) {
                     $year = $iYear + 1900;
                 } else {
                     $year = $iYear + 2000;
                 }
             }
             $year = (int) $year;
         } elseif ($token == 'MM' || $token == 'M') {
             $month = $this->getInteger($value, $i_val, $this->length($token), 2);
             $iMonth = (int) $month;
             if ($month === null || $iMonth < 1 || $iMonth > 12) {
                 return null;
             }
             //throw new TInvalidDataValueException('Invalid month', $value);
             $i_val += strlen($month);
             $month = $iMonth;
         } elseif ($token == 'dd' || $token == 'd') {
             $day = $this->getInteger($value, $i_val, $this->length($token), 2);
             $iDay = (int) $day;
             if ($day === null || $iDay < 1 || $iDay > 31) {
                 return null;
             }
             //throw new TInvalidDataValueException('Invalid day', $value);
             $i_val += strlen($day);
             $day = $iDay;
         } else {
             if ($this->substring($value, $i_val, $this->length($token)) != $token) {
                 return null;
             } else {
                 $i_val += $this->length($token);
             }
         }
     }
     if ($i_val != $this->length($value)) {
         return null;
     }
     //throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value);
     if (!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) {
         return null;
     } else {
         if (empty($year)) {
             $year = date('Y');
         }
         $day = (int) $day <= 0 ? 1 : (int) $day;
         $month = (int) $month <= 0 ? 1 : (int) $month;
         $s = new TDateTimeStamp();
         return $s->getTimeStamp(0, 0, 0, $month, $day, $year);
     }
 }
示例#3
0
 /**
  * Renders the drop down list date picker.
  */
 protected function renderDropDownListCalendar($writer)
 {
     if ($this->getMode() == TDatePickerMode::Basic) {
         $this->setMode(TDatePickerMode::ImageButton);
     }
     parent::addAttributesToRender($writer);
     $writer->removeAttribute('name');
     $writer->removeAttribute('type');
     $writer->addAttribute('id', $this->getClientID());
     if (strlen($class = $this->getCssClass()) > 0) {
         $writer->addAttribute('class', $class);
     }
     $writer->renderBeginTag('span');
     $s = new TDateTimeStamp();
     $date = $s->getDate($this->getTimeStampFromText());
     //$date = @getdate($this->getTimeStampFromText());
     $this->renderCalendarSelections($writer, $date);
     //render a hidden input field
     $writer->addAttribute('name', $this->getUniqueID());
     $writer->addAttribute('type', 'hidden');
     $writer->addAttribute('value', $this->getText());
     $writer->renderBeginTag('input');
     $writer->renderEndTag();
     $writer->renderEndTag();
 }
示例#4
0
 /**
  * Client-side Text property can only be updated after the OnLoad stage.
  * @param string text content for the textbox
  */
 public function setText($value)
 {
     if (parent::getText() === $value) {
         return;
     }
     parent::setText($value);
     if ($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData()) {
         $cb = $this->getPage()->getCallbackClient();
         $cb->setValue($this, $value);
         if ($this->getInputMode() == TDatePickerInputMode::DropDownList) {
             $s = new TDateTimeStamp();
             $date = $s->getDate($this->getTimeStampFromText());
             $id = $this->getClientID();
             $cb->select($id . TControl::CLIENT_ID_SEPARATOR . 'day', 'Value', $date['mday'], 'select');
             $cb->select($id . TControl::CLIENT_ID_SEPARATOR . 'month', 'Value', $date['mon'] - 1, 'select');
             $cb->select($id . TControl::CLIENT_ID_SEPARATOR . 'year', 'Value', $date['year'], 'select');
         }
     }
 }
示例#5
0
 protected function getDateTimeValue($container, $column, $record)
 {
     if (preg_match('/timestamp/i', $column->getDbType())) {
         $time = $container->findControl(self::DEFAULT_ID)->getTimestamp();
         $s = new TDateTimeStamp();
         $date = $s->getDate($time);
         $hour = $container->findControl('scaffold_time_hour')->getSelectedValue();
         $mins = $container->findControl('scaffold_time_min')->getSelectedValue();
         $secs = $container->findControl('scaffold_time_sec')->getSelectedValue();
         return $s->getTimeStamp($hour, $mins, $secs, $date['mon'], $date['mday'], $date['year']);
     } else {
         return parent::getDateTimeValue($container, $column, $record);
     }
 }