GravityKit\GravityMigrate\Schema\GfDateFormat
The date formats Gravity Forms accepts, and how they read on other platforms.
Gravity Forms encodes the field order and the separator in one slug, and it accepts exactly seven of them. GF_Field_Date::sanitize_settings() silently rewrites anything else to mdy, so a plausible-looking value such as ymd or mdy_dash is not a partial loss: it is a total one, and the form shows American dates with nothing said.
Two asymmetries:
- Gravity Forms offers a slash order for ymd but writes it ymd_slash, not ymd.
- Gravity Forms offers no dash or dot variant of mdy, so a platform that has one cannot be represented and the caller has to be told.
Since: %ver%
Source: src/Schema/GfDateFormat.php:26
Details
- Kind:
class - Namespace:
GravityKit\GravityMigrate\Schema
Methods
| Method | Description |
|---|---|
is_valid() | Determines whether Gravity Forms will keep the given format. |
from_parts() | Returns the closest format Gravity Forms will keep. |
from_php() | Reads a PHP date format string into a Gravity Forms format slug. |
to_php() | Writes a Gravity Forms format slug as a PHP date format. |
to_ninja() | Writes a Gravity Forms format slug as a Ninja Forms date_format token. |
from_ninja() | Reads a Ninja Forms date_format token into a Gravity Forms format slug. |
Method Reference
is_valid()
public static function is_valid( string $format ): bool
Determines whether Gravity Forms will keep the given format.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$format | string | Candidate format slug. |
Returns
bool
Since: %ver%
Source: src/Schema/GfDateFormat.php:63
from_parts()
public static function from_parts( string $order, string $separator ): string
Returns the closest format Gravity Forms will keep.
Gravity Forms has no dash or dot variant of mdy, so those fall back to the slash form rather than to the unrelated default.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$order | string | Field order: mdy, dmy or ymd. | |
$separator | string | Separator character. |
Returns
string
Since: %ver%
Source: src/Schema/GfDateFormat.php:80
from_php()
public static function from_php( string $format ): ?string
Reads a PHP date format string into a Gravity Forms format slug.
Accepts the partial formats some platforms allow (d/m with no year) by treating the missing part as implied, since the order and separator still carry.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$format | string | PHP date format, such as d-m-Y. |
Returns
string|null— Null when nothing date-like was found.
Since: %ver%
Source: src/Schema/GfDateFormat.php:108
to_php()
public static function to_php( string $format ): string
Writes a Gravity Forms format slug as a PHP date format.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$format | string | Gravity Forms format slug. |
Returns
string
Since: %ver%
Source: src/Schema/GfDateFormat.php:215
to_ninja()
public static function to_ninja( string $format ): string
Writes a Gravity Forms format slug as a Ninja Forms date_format token.
Ninja spells its formats out in Moment tokens (DD/MM/YYYY), listed in includes/Config/FieldSettings.php.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$format | string | Gravity Forms format slug. |
Returns
string
Since: %ver%
Source: src/Schema/GfDateFormat.php:245
from_ninja()
public static function from_ninja( string $format ): ?string
Reads a Ninja Forms date_format token into a Gravity Forms format slug.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$format | string | Ninja Forms token, such as DD-MM-YYYY. |
Returns
string|null— Null for "default" or a token with no date parts.
Since: %ver%
Source: src/Schema/GfDateFormat.php:275