Creates a DateTime by adding or subtacting interval.

@param   integer  $value   The value for the format.
@param   string   $format  The interval_spec for sprintf(), eg. 'P%sD'.

@return  DateTime

@since   2.0.0
485394
private function calc($value, $format)
	{
		$value = intval($value);
		$spec = sprintf($format, abs($value));

		return $value > 0 ? $this->add(new DateInterval($spec)) : $this->sub(new DateInterval($spec));
	}
939306
public static function createFromFormat($format, $datetime, $timezone = null)
    {
        $datepoint = parent::createFromFormat($format, $datetime, $timezone);
        if (false !== $datepoint) {
            return self::create($datepoint);
        }

        return $datepoint;
    }
677607
public static function date($format = "Y-m-d H:i:s", $time = null)
    {
        $time = ($time !== null ? $time : time());

        if (!is_numeric($time)) {
            $time = static::toUnix($time);
        }

        return date($format, $time);
    }
1278619
public function add($value, $format = '(%s)')
	{
		array_push($this->pattern, sprintf($format, $this->sanitize($value)));

		return $this;
	}
588720
public static function castToDateTime($value)
    {
        if ($value instanceof \DateTime) {
            return clone $value;
        }
        if (is_numeric($value)) {
            $date = new \DateTime();
            $date->setTimestamp((int)$value);
        } elseif (is_string($value) || (is_object($value) && method_exists($value, '__toString'))) {
            $date = date_create((string)$value);
            if ($date === false) {
                $date = null;
            }
        } else {
            $date = null;
        }
        return $date;
    }
513984
private static function fromTimestamp($value)
    {
        $result = false;
        if (empty($value)) {
            return $result;
        }

        $result = new \DateTime($value);

        return $result->getTimestamp();
    }
358174
public static function phone($value, $format) {
        $value = preg_replace('/[^0-9]+/', '', $value);

        if (is_array($format)) {
            $length = mb_strlen($value);

            if ($length >= 11) {
                $format = $format[11];
            } else if ($length >= 10) {
                $format = $format[10];
            } else {
                $format = $format[7];
            }
        }

        return static::format($value, $format);
    }
878912
public function buildTime($value)
    {
        if ($value instanceof \DateTime) {
            return $value->format(static::TIME_FORMAT);
        } elseif (is_int($value)) {
            $date = new \DateTime();
            $date->setTimestamp($value);

            return $date->format(static::TIME_FORMAT);
        } elseif (is_string($value)) {
            $date = new \DateTime($value);

            return $date->format(static::TIME_FORMAT);
        }
        throw new \InvalidArgumentException('Time value should be int, string or \DateTime');
    }
563405
protected function formatDate($value)
    {
        $format = null;
        if (isset($this->input) && $this->input->hasOption('date-fmt')) {
            $format = $this->input->getOption('date-fmt');
        }
        if ($format === null) {
            $format = $this->config->getWithDefault('application.date_format', 'c');
        }

        // Workaround for the ssl.expires_on date, which is currently a
        // timestamp in milliseconds.
        if (substr($value, -3) === '000' && strlen($value) === 13) {
            $value = substr($value, 0, 10);
        }

        $timestamp = is_numeric($value) ? $value : strtotime($value);

        return $timestamp === false ? null : date($format, $timestamp);
    }
970735
public function add(string $interval, $format = ''){
    $tmp  = new \bbn\time($this->format());
    $tmp->time->add($this->get_interval($interval));
    return $tmp->format($format);
  }
204634
public function buildDateTime($value)
    {
        if ($value instanceof \DateTime) {
            return $value->format(static::DATE_TIME_FORMAT);
        } elseif (is_int($value)) {
            $date = new \DateTime();
            $date->setTimestamp($value);

            return $date->format(static::DATE_TIME_FORMAT);
        } elseif (is_string($value)) {
            $date = new \DateTime($value);

            return $date->format(static::DATE_TIME_FORMAT);
        }
        throw new \InvalidArgumentException('DateTime value should be int, string or \DateTime');
    }
273087
public static function getDateTime($value) : DateTimeInterface
    {
        $datetime  = false;
        $exception = null;

        if ($value instanceof DateTimeInterface) {
            return $value;
        } elseif ($value instanceof UTCDateTime) {
            $datetime = $value->toDateTime();
            $datetime->setTimezone(new DateTimeZone(date_default_timezone_get()));
        } elseif (is_numeric($value)) {
            $value         = (float) $value;
            $seconds       = (int) $value;
            $microseconds  = abs(round($value - $seconds, 6));
            $microseconds *= 1000000;

            $datetime = static::craftDateTime($seconds, (int) $microseconds);
        } elseif (is_string($value)) {
            try {
                $datetime = new DateTime($value);
            } catch (Throwable $e) {
                $exception = $e;
            }
        }

        if ($datetime === false) {
            throw new InvalidArgumentException(sprintf('Could not convert %s to a date value', is_scalar($value) ? '"' . $value . '"' : gettype($value)), 0, $exception);
        }

        return $datetime;
    }
762491
public function fromDateTime($value)
    {
        $format = $this->getDateFormat();

        // If the value is already a DateTime instance, we will just skip the rest of
        // these checks since they will be a waste of time, and hinder performance
        // when checking the field. We will just return the DateTime right away.
        if ($value instanceof DateTime)
        {
            //
        }

        // If the value is totally numeric, we will assume it is a UNIX timestamp and
        // format the date as such. Once we have the date in DateTime form we will
        // format it according to the proper format for the database connection.
        elseif (is_numeric($value))
        {
            $value = Carbon::createFromTimestamp($value);
        }

        // If the value is in simple year, month, day format, we will format it using
        // that setup. This is for simple "date" fields which do not have hours on
        // the field. This conveniently picks up those dates and format correct.
        elseif (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $value))
        {
            $value = Carbon::createFromFormat('Y-m-d', $value)->startOfDay();
        }

        // If this value is some other type of string, we'll create the DateTime with
        // the format used by the database connection. Once we get the instance we
        // can return back the finally formatted DateTime instances to the devs.
        elseif ( ! $value instanceof DateTime)
        {
            $value = Carbon::createFromFormat($format, $value);
        }

        return $value->format($format);
    }
254183
protected static function createDate(string $date, string $format = 'Y-m-d'): \DateTime
    {
        return \DateTime::createFromFormat($format, $date);
    }
662706
public function dateFormat($value, $format = 'd/m/Y')
    {
        if (!empty($value)) {

            // passage de la date en datetime
            if (strlen($value) == 10) {
                $value .= ' 00:00:00';
            }

            // gestion d'une date vide
            if ($value == '0000-00-00 00:00:00') {
                $value = '';
            } else {
                $date = \DateTime::createFromFormat('Y-m-d H:i:s',$value);
                //Check que la value est compatible avec le format
                if($date !== false  && !array_sum($date->getLastErrors())){
                    $value = $date->format($format);
                }
            }
        }

        return $value;
    }
167303
static public function timestamp($value)
    {
        $value || $value = time();
        if(is_numeric($value)) {
            //$value = strftime('%Y-%m-%d %H:%M:%S', $value);
            $value = strftime('%Y-%m-%d %H:%M:%S', $value);
        }
        
        return $value;
    }
1043198
public function dateIs(\DateTime $value)
    {
        $this->add(new Criterium(self::CRITERIUM_DATE_IS, $value));

        return $this;
    }