returns formatted date/time string

@param   string                   $format    format, see http://php.net/date
@param   \stubbles\date\TimeZone  $timeZone  target time zone of formatted string
@return  string
326595
public function format(string $format, TimeZone $timeZone = null): string
    {
        if (null !== $timeZone) {
            return $timeZone->translate($this)->format($format);
        }

        return $this->dateTime->format($format);
    }
535962
public function format($format)
    {
        $format = preg_replace_callback('/(?<!\\\\)[DlFM]/', array($this, '_translate'), $format);
        return $this->_date->format($format);
    }
352362
public function format($date, $format)
    {
        if ($date instanceof \DateTimeInterface) {
            return $date->format($format);
        } elseif ($date instanceof \DateInterval) {
            return $date->format($format);
        } elseif ($date === 'now') {
            return date($format);
        } else {
            $timestamp = (integer)$date;
            return date($format, $timestamp);
        }
    }
551917
public function dateFormat($date, string $format = 'M d Y'): string
    {
        if ($date instanceof DateTime) {
            return $date->format($format);
        } elseif (is_int($date)) {
            return date($format, $date);
        }

        return date($format, strtotime($date));
    }
220460
public function dateTimeWithTimezone(string $format = TimezonedDateTime::DISPLAY_FORMAT) : TimezonedDateTimeFieldBuilder
    {
        return new TimezonedDateTimeFieldBuilder($this->field->type(new TimezonedDateTimeType($format)));
    }
1075641
public function getTime($format = null)
    {
        //argument 1 must be a string or null
        Argument::i()->test(1, 'string', 'null');

        $time = $this->time + $this->offset;

        if (!is_null($format)) {
            return date($format, $time);
        }

        return $time;
    }
507069
public static function date_format($format = null)
    {
        if (empty($format)) {
            $format = 'd-M-Y H:i:s O';
        }

        if (strpos($format, 'u') !== false) {
            $dt  = number_format(microtime(true), 6, '.', '');
            $dt .=  '.' . date_default_timezone_get();

            if ($date = date_create_from_format('U.u.e', $dt)) {
                return $date->format($format);
            }
        }

        return date($format);
    }
1202500
public function formatTimepoint($time, $format)
    {
        if ($time instanceof TimePoint) {
            return $time->format($format, $this->displayTimezone);
        }

        if ($time instanceof DateTime) {
            $formatted = clone $time;
            $formatted->setTimezone(new DateTimeZone($this->displayTimezone));
            return $formatted->format($format);
        }

        return '';
    }
592649
public function format($format)
    {
        $timestamp = mktime(
            $this->hour,
            $this->minute,
            $this->second,
            $this->month,
            $this->day,
            $this->year
        );
        return strftime($format, $timestamp);
    }
657034
public static function timeFormat($timestamp = null, $format = 'Y-m-d H:i:s')
    {
        if ($timestamp === null) {
            $timestamp = time();
        } elseif (empty($timestamp)) {
            return null;
        } else {
            $timestamp = intval($timestamp);
        }
        if (strncmp($format, 'php:', 4) === 0) {
            $format = substr($format, 4);
        }
        
        return date($format, $timestamp);
    }
1087450
public function getTime(string $format = null)
    {
        $time = $this->time + $this->offset;

        if (!is_null($format)) {
            return date($format, $time);
        }

        return $time;
    }
372607
public static function formatDate($format, $timestamp)
    {
        static $datesPatterns = null;
        static $timesPatterns = null;

        if ($datesPatterns === null || $timesPatterns === null) {
            $datesPatterns = "/\b(" . implode('|', array_keys(static::$_map['date'])) . ")\b(?![^']*'(?:(?:[^']*'){2})*[^']*$)/i";
            $timesPatterns = "/\b(" . implode('|', array_keys(static::$_map['time'])) . ")\b(?![^']*'(?:(?:[^']*'){2})*[^']*$)/i";
        }

        // normalize formats
        $result = preg_replace_callback($datesPatterns, function ($matches) use ($timestamp) {
            return date(static::$_map['date'][$matches[1]], $timestamp);
        }, trim($format));

        $result = preg_replace_callback($timesPatterns, function ($matches) use ($timestamp) {
            return date(static::$_map['time'][$matches[1]], $timestamp);
        }, $result);

        return str_replace('\'', '', $result);
    }
743180
public function format($format, $value)
    {
        switch ($format) {
            case 'date-time':
                return $this->formatDateTime($value);
            case 'date-time-http':
                return $this->formatDateTimeHttp($value);
            case 'date':
                return $this->formatDate($value);
            case 'time':
                return $this->formatTime($value);
            case 'timestamp':
                return $this->formatTimestamp($value);
            case 'boolean-string':
                return $this->formatBooleanAsString($value);
            default:
                return $value;
        }
    }
752151
public static function getFormattedDateTime(\DateTime $val, string $format = \DateTime::ATOM): string
    {
        return StringHelper::dateFormat($val, $format);
    }
1123756
public static function parse($format, $time, DateTimeZone $timezone =  NULL) {
    if (!isset($timezone) && date_default_timezone_get() != '') {
      $timezone = new DateTimeZone(date_default_timezone_get());
    }

    $ret = parent::createFromFormat($format, $time, $timezone);
    
    if ($ret === FALSE) {
      throw new ParsingException('Aus '.Code::varInfo($time).' konnte keinen Zeitinformationen des Formates: '.Code::varInfo($format).' geparst werden. lastErrors: '.print_r(DateTime::getLastErrors(),true));
    }
    
    return new static($ret);
  }
180933
public function format($format = 'local', $timezone = null)
	{
		// custom format pattern lookup
		if (array_key_exists($format, static::$patterns))
		{
			$format = static::$patterns[$format];
		}

		// save the objects timezone
		$orginalTimezone = $this->datetime->getTimezone();

		// default GMT offset
		$offset = 0;

		// want to output in the application default timezone?
		if ($timezone === true)
		{
			$timezone = static::defaultTimezone();
		}

		// output timezone specified?
		elseif ($timezone)
		{
			if ( ! $timezone instanceOf DateTimeZone)
			{
				$this->datetime->setTimezone($timezone = new DateTimeZone($timezone));
			}
		}

		// output in the current timezone
		else
		{
			$timezone = $orginalTimezone;
		}


		// strftime will always do UTC to local time, and
		// strptime() does timezones but no daylight savings,
		// so we might need a correction here

		// offsets are to UTC, so first, UTC -> given timezone, second, UTC -> current object timezone
		$testdate1 = new DateTime('@'.$this->datetime->getTimestamp(), $orginalTimezone);
		$testdate2 = new DateTime('@'.$this->datetime->getTimestamp(), $timezone);

		// offset is the delta between both
		$offset = $timezone->getOffset($testdate1) - $orginalTimezone->getOffset($testdate2);

		// Create output
		if (strpos($format, '%') === false)
		{
			$result = $this->datetime->format($format);
		}
		else
		{
			$result = strftime($format, $this->datetime->getTimestamp() + $offset);
			if (static::$encoding)
			{
				$result = static::$encoding == 'UTF8' ? utf8_encode($result) : iconv('ISO8859-1', static::$encoding, $result);
			}
		}

		// restore the timezone if needed
		if ($timezone !== null)
		{
			$this->datetime->setTimezone($orginalTimezone);
		}

		return $result;
	}
1205965
public function format_local($format) {
        // Configure the timezone to account for timezone and/or daylight savings time
        $timezone = new DateTimeZone(date_default_timezone_get());
        $this->setTimezone($timezone);

        $timestamp = $this->getTimestamp();
        return strftime($format, $timestamp);
    }