Ejemplo n.º 1
0
 /**
  * Creates the time to represent, no timezone is allowed since times don't have timezones
  * 
  * @throws fValidationException  When `$time` is not a valid time
  * 
  * @param  fTime|object|string|integer $time  The time to represent, `NULL` is interpreted as now
  * @return fTime
  */
 public function __construct($time = NULL)
 {
     if ($time === NULL) {
         $timestamp = time();
     } elseif (is_numeric($time) && ctype_digit($time)) {
         $timestamp = (int) $time;
     } elseif (is_string($time) && in_array(strtoupper($time), array('CURRENT_TIMESTAMP', 'CURRENT_TIME'))) {
         $timestamp = time();
     } else {
         if (is_object($time) && is_callable(array($time, '__toString'))) {
             $time = $time->__toString();
         } elseif (is_numeric($time) || is_object($time)) {
             $time = (string) $time;
         }
         $time = fTimestamp::callUnformatCallback($time);
         $timestamp = strtotime($time);
     }
     $is_51 = fCore::checkVersion('5.1');
     $is_valid = $is_51 && $timestamp !== FALSE || !$is_51 && $timestamp !== -1;
     if (!$is_valid) {
         throw new fValidationException('The time specified, %s, does not appear to be a valid time', $time);
     }
     $this->time = strtotime(date('1970-01-01 H:i:s', $timestamp));
 }
Ejemplo n.º 2
0
 /**
  * Creates the date to represent, no timezone is allowed since dates don't have timezones
  *
  * @throws fValidationException  When `$date` is not a valid date
  *
  * @param  fDate|object|string|integer $date  The date to represent, `NULL` is interpreted as today
  * @return fDate
  */
 public function __construct($date = NULL)
 {
     if ($date === NULL) {
         $timestamp = time();
     } elseif (is_numeric($date) && preg_match('#^-?\\d+$#D', $date)) {
         $timestamp = (int) $date;
     } elseif (is_string($date) && in_array(strtoupper($date), array('CURRENT_TIMESTAMP', 'CURRENT_DATE'))) {
         $timestamp = time();
     } else {
         if (is_object($date) && is_callable(array($date, '__toString'))) {
             $date = $date->__toString();
         } elseif (is_numeric($date) || is_object($date)) {
             $date = (string) $date;
         }
         $date = fTimestamp::callUnformatCallback($date);
         $timestamp = strtotime(fTimestamp::fixISOWeek($date));
     }
     $is_51 = fCore::checkVersion('5.1');
     $is_valid = $is_51 && $timestamp !== FALSE || !$is_51 && $timestamp !== -1;
     if (!$is_valid) {
         throw new fValidationException('The date specified, %s, does not appear to be a valid date', $date);
     }
     $this->date = strtotime(date('Y-m-d 00:00:00', $timestamp));
 }