Ejemplo n.º 1
0
 /**
  * Date/time formatter
  *
  * Converts a date, specified in $input_format format, in the $format
  * format and returns the result. If $input is not defined, the current
  * time is used as input.
  *
  * The $format parameter can be one of the following values:
  * - 'date' for a string with a date description (current locale)
  * - 'date_sql' for date in common SQL format ('%Y-%m-%d')
  * - 'date_iso8601' same as 'date_sql'
  * - 'datetime' for a string with date and time description (current locale)
  * - 'datetime_sql' for a string with a time description as '%Y-%m-%d %H:%M:%S'
  * - 'datetime_iso8601' for a string with time description in ISO 8601 format
  * - 'datetime_rfc3339' for a string as described in RFC3339 (atom format)
  *
  * Any other value will be passed directly to strftime().
  *
  * The $input_format parameter can be one of the following values:
  * - 'timestamp' for UNIX timestamps
  * - 'sql' for common SQL date/datetime
  *
  * @param  string     $format       The format of the resulting date
  * @param  mixed      $input        The source date to format
  * @param  string     $input_format The format of the source date
  * @return mixed|null               The formatted date or null on errors
  */
 public static function formatDate($format, $input = null, $input_format = 'timestamp')
 {
     if (is_null($input)) {
         $timestamp = time();
     } elseif ($input_format == 'timestamp') {
         $timestamp = $input;
     } else {
         $timestamp = TIP::getTimestamp($input, $input_format);
     }
     return empty($timestamp) ? null : TIP::_formatTimestamp($timestamp, $format);
 }