# BaseFormatConverter

> BaseFormatConverter provides concrete implementation for yii\helpers\FormatConverter.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [helpers](/docs/api/yii/helpers/index.md) › BaseFormatConverter

| class | `yii\helpers\BaseFormatConverter` |
| --- | --- |
| Since | 2.0 |
| Source | [`framework/helpers/BaseFormatConverter.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/helpers/BaseFormatConverter.php#L23) |

1 subclass:

- [`FormatConverter`](/docs/api/yii/helpers/formatconverter/index.md)

BaseFormatConverter provides concrete implementation for [`FormatConverter`](/docs/api/yii/helpers/formatconverter/index.md).

Do not use BaseFormatConverter. Use [`FormatConverter`](/docs/api/yii/helpers/formatconverter/index.md) instead.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$juiFallbackDatePatterns`](#property-juiFallbackDatePatterns) static | `array` | The jQuery UI fallback definition to use for the ICU short patterns `short`, `medium`, `long` and `full`. Default: `['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']]`. | `BaseFormatConverter` |
| [`$phpFallbackDatePatterns`](#property-phpFallbackDatePatterns) static | `array` | The php fallback definition to use for the ICU short patterns `short`, `medium`, `long` and `full`. Default: `['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']]`. | `BaseFormatConverter` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`convertDateIcuToJui()`](#method-convertDateIcuToJui) static | 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). | `BaseFormatConverter` |
| [`convertDateIcuToPhp()`](#method-convertDateIcuToPhp) static | 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). | `BaseFormatConverter` |
| [`convertDatePhpToIcu()`](#method-convertDatePhpToIcu) static | 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). | `BaseFormatConverter` |
| [`convertDatePhpToJui()`](#method-convertDatePhpToJui) static | 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). | `BaseFormatConverter` |

## Property details

### $juiFallbackDatePatterns <span id="property-juiFallbackDatePatterns"></span>

```php
public static array $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 <span id="property-phpFallbackDatePatterns"></span>

```php
public static array $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.

## Method details

### convertDateIcuToJui() <span id="method-convertDateIcuToJui"></span>

```php
public static function convertDateIcuToJui(string $pattern, string $type = 'date', string|null $locale = null): 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).

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$pattern` | `string` | Date format pattern in ICU format. |
| `$type` | `string` | 'date', 'time', or 'datetime'. |
| `$locale` | `string\|null` | The locale to use for converting ICU short patterns `short`, `medium`, `long` and `full`. If not given, `Yii::$app->language` will be used. |

**Returns**

`string`: The converted date format pattern.

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php)

### convertDateIcuToPhp() <span id="method-convertDateIcuToPhp"></span>

```php
public static function convertDateIcuToPhp(string $pattern, string $type = 'date', string|null $locale = null): 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).

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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$pattern` | `string` | Date format pattern in ICU format. |
| `$type` | `string` | 'date', 'time', or 'datetime'. |
| `$locale` | `string\|null` | The locale to use for converting ICU short patterns `short`, `medium`, `long` and `full`. If not given, `Yii::$app->language` will be used. |

**Returns**

`string`: The converted date format pattern.

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php)

### convertDatePhpToIcu() <span id="method-convertDatePhpToIcu"></span>

```php
public static function convertDatePhpToIcu(string $pattern): 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).

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

Since 2.0.13 it handles escaped characters correctly.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$pattern` | `string` | Date format pattern in PHP `date()` function format. |

**Returns**

`string`: The converted date format pattern.

### convertDatePhpToJui() <span id="method-convertDatePhpToJui"></span>

```php
public static function convertDatePhpToJui(string $pattern): 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).

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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$pattern` | `string` | Date format pattern in PHP `date()` function format. |

**Returns**

`string`: The converted date format pattern.