getTimeStamp() public method

public getTimeStamp ( $hr, $min, $sec, $mon = false, $day = false, $year = false, $is_gmt = false ) : integer | float
return integer | float a timestamp given a local time
コード例 #1
0
 public function assertIsValidDate($y1, $m, $d = 13)
 {
     $s = new TDateTimeStamp();
     $t = $s->getTimeStamp(0, 0, 0, $m, $d, $y1);
     $rez = $s->formatDate('Y-n-j H:i:s', $t);
     $this->assertEquals("{$y1}-{$m}-{$d} 00:00:00", $rez);
 }
コード例 #2
0
ファイル: TDatePicker.php プロジェクト: pradosoft/prado
 /**
  * Loads date from drop down list data.
  * @param string the key that can be used to retrieve data from the input data collection
  * @param array the input data collection
  * @return array the date selected
  */
 protected function getDateFromPostData($key, $values)
 {
     $date = @getdate();
     $pattern = $this->getDateFormat();
     $pattern = str_replace(array('MMMM', 'MMM'), array('MM', 'MM'), $pattern);
     $formatter = new TSimpleDateFormatter($pattern);
     $order = $formatter->getDayMonthYearOrdering();
     if (isset($values[$key . '$day'])) {
         $day = intval($values[$key . '$day']);
     } elseif (in_array('day', $order)) {
         $day = $date['mday'];
     } else {
         $day = 1;
     }
     if (isset($values[$key . '$month'])) {
         $month = intval($values[$key . '$month']) + 1;
     } else {
         $month = $date['mon'];
     }
     if (isset($values[$key . '$year'])) {
         $year = intval($values[$key . '$year']);
     } else {
         $year = $date['year'];
     }
     $s = new TDateTimeStamp();
     $date = $s->getTimeStamp(0, 0, 0, $month, $day, $year);
     //$date = @mktime(0, 0, 0, $month, $day, $year);
     $pattern = $this->getDateFormat();
     $pattern = str_replace(array('MMMM', 'MMM'), array('MM', 'MM'), $pattern);
     $formatter = new TSimpleDateFormatter($pattern);
     return $formatter->format($date);
 }
コード例 #3
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);
     }
 }
コード例 #4
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);
     }
 }