HumHub Documentation (unofficial)

FormatConverter extends BaseFormatConverter
in package

FormatConverter provides functionality to convert between different formatting pattern formats.

It provides functions to convert date format patterns between different conventions.

Tags
author

Carsten Brandt mail@cebe.cc

author

Enrica Ruedin e.ruedin@guggach.com

since
2.0

Table of Contents

Properties

$juiFallbackDatePatterns  : array<string|int, mixed>
$phpFallbackDatePatterns  : array<string|int, mixed>
$_icuShortFormats  : mixed

Methods

convertDateIcuToJui()  : string
Converts a date format pattern from [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax) to [jQuery UI date format](https://api.jqueryui.com/datepicker/#utility-formatDate).
convertDateIcuToPhp()  : string
Converts a date format pattern from [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax) to [PHP `date()` function format](https://www.php.net/manual/en/function.date).
convertDatePhpToIcu()  : string
Converts a date format pattern from [PHP `date()` function format](https://www.php.net/manual/en/function.date) to [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax).
convertDatePhpToJui()  : string
Converts a date format pattern from [PHP `date()` function format](https://www.php.net/manual/en/function.date) to [jQuery UI date format](https://api.jqueryui.com/datepicker/#utility-formatDate).
createFormatter()  : string
Creates a date/time formatter based on the given parameters.

Properties

$juiFallbackDatePatterns

public static array<string|int, mixed> $juiFallbackDatePatterns = ['short' => ['date' => 'd/m/y', 'time' => '', 'datetime' => 'd/m/y'], 'medium' => ['date' => 'M d, yy', 'time' => '', 'datetime' => 'M d, yy'], 'long' => ['date' => 'MM d, yy', 'time' => '', 'datetime' => 'MM d, yy'], 'full' => ['date' => 'DD, MM d, yy', 'time' => '', 'datetime' => 'DD, MM d, yy']]

the jQuery UI fallback definition to use for the ICU short patterns short, medium, long and full. This is used as fallback when the intl extension is not installed.

$phpFallbackDatePatterns

public static array<string|int, mixed> $phpFallbackDatePatterns = ['short' => ['date' => 'n/j/y', 'time' => 'H:i', 'datetime' => 'n/j/y H:i'], 'medium' => ['date' => 'M j, Y', 'time' => 'g:i:s A', 'datetime' => 'M j, Y g:i:s A'], 'long' => ['date' => 'F j, Y', 'time' => 'g:i:sA', 'datetime' => 'F j, Y g:i:sA'], 'full' => ['date' => 'l, F j, Y', 'time' => 'g:i:sA T', 'datetime' => 'l, F j, Y g:i:sA T']]

the php fallback definition to use for the ICU short patterns short, medium, long and full. This is used as fallback when the intl extension is not installed.

$_icuShortFormats

private static mixed $_icuShortFormats = [ 'short' => 3, // IntlDateFormatter::SHORT, 'medium' => 2, // IntlDateFormatter::MEDIUM, 'long' => 1, // IntlDateFormatter::LONG, 'full' => 0, ]

Methods

convertDateIcuToJui()

Converts a date format pattern from [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax) to [jQuery UI date format](https://api.jqueryui.com/datepicker/#utility-formatDate).

public static convertDateIcuToJui(string $pattern[, string $type = 'date' ][, string|null $locale = null ]) : string

Pattern constructs that are not supported by the jQuery UI format will be removed.

Parameters
$pattern : string

date format pattern in ICU format.

$type : string = 'date'

'date', 'time', or 'datetime'.

$locale : string|null = null

the locale to use for converting ICU short patterns short, medium, long and full. If not given, Yii::$app->language will be used.

Tags
throws
Exception
Return values
string

The converted date format pattern.

convertDateIcuToPhp()

Converts a date format pattern from [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax) to [PHP `date()` function format](https://www.php.net/manual/en/function.date).

public static convertDateIcuToPhp(string $pattern[, string $type = 'date' ][, string|null $locale = null ]) : string

The conversion is limited to date patterns that do not use escaped characters. Patterns like d 'of' MMMM yyyy which will result in a date like 1 of December 2014 may not be converted correctly because of the use of escaped characters.

Pattern constructs that are not supported by the PHP format will be removed.

Parameters
$pattern : string

date format pattern in ICU format.

$type : string = 'date'

'date', 'time', or 'datetime'.

$locale : string|null = null

the locale to use for converting ICU short patterns short, medium, long and full. If not given, Yii::$app->language will be used.

Tags
throws
Exception
Return values
string

The converted date format pattern.

convertDatePhpToIcu()

Converts a date format pattern from [PHP `date()` function format](https://www.php.net/manual/en/function.date) to [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax).

public static convertDatePhpToIcu(string $pattern) : string

Pattern constructs that are not supported by the ICU format will be removed.

Since 2.0.13 it handles escaped characters correctly.

Parameters
$pattern : string

date format pattern in PHP date() function format.

Return values
string

The converted date format pattern.

convertDatePhpToJui()

Converts a date format pattern from [PHP `date()` function format](https://www.php.net/manual/en/function.date) to [jQuery UI date format](https://api.jqueryui.com/datepicker/#utility-formatDate).

public static convertDatePhpToJui(string $pattern) : string

The conversion is limited to date patterns that do not use escaped characters. Patterns like jS \o\f F Y which will result in a date like 1st of December 2014 may not be converted correctly because of the use of escaped characters.

Pattern constructs that are not supported by the jQuery UI format will be removed.

Parameters
$pattern : string

date format pattern in PHP date() function format.

Return values
string

The converted date format pattern.

createFormatter()

Creates a date/time formatter based on the given parameters.

private static createFormatter(string|null $locale, string $type, string $pattern) : string
Parameters
$locale : string|null

The locale to be used. If null, the application's current language will be used.

$type : string

The type of formatter ('date', 'time', etc.)

$pattern : string

The pattern for the IntlDateFormatter.

Tags
throws
Exception

If the 'intl' extension is not loaded.

Return values
string

The resulting pattern after formatter creation.


        
On this page

Search results