FormatterDateTimeToJson
in package
implements
FormatterInterface
Formatter DateTime to Json
This formatter converts date/time string values assumed to be in server timezone to UTC time and formats to the JSON standard 'Y-m-d\TH:i:s.000\Z'.
For values that should always be displayed as is, we should not use this formatter but instead use only the 'date' valitator. For exmaple we use this formatter on 'survey.dateCreated' but not on 'survey.expires' or 'survey.startDate' because we want to display and edit the values of 'survey.expires' or 'survey.startDate' using the server timezone not the local timezone.
Table of Contents
Interfaces
Properties
- $inputTimezone : string
- $name : string
- $revert : bool
Methods
- __construct() : mixed
- format() : mixed|null
- Cast UTC datetime string to JSON datetime string
- setClassBasedOnConfig() : void
- Checks config for this specific formatter, and adjusts class properties based on the config.
- apply() : string|null
- Cast UTC datetime string to JSON datetime string
- dateFormat() : string|null
- Date format
- revert() : string|null
- Cast JSON datetime string to UTC datetime string
Properties
$inputTimezone
private
string
$inputTimezone
$name
private
string
$name
= 'dateTimeToJson'
$revert
private
bool
$revert
= false
Methods
__construct()
public
__construct([bool $revert = false ][, string|null $inputTimezone = null ]) : mixed
Parameters
- $revert : bool = false
-
If true performs reverse format conversion
- $inputTimezone : string|null = null
-
Defaults to date_default_timezone_get()
format()
Cast UTC datetime string to JSON datetime string
public
format(mixed|null $value, array<string|int, mixed> $config[, array<string|int, mixed> $options = [] ]) : mixed|null
Parameters
- $value : mixed|null
- $config : array<string|int, mixed>
- $options : array<string|int, mixed> = []
Tags
Return values
mixed|nullsetClassBasedOnConfig()
Checks config for this specific formatter, and adjusts class properties based on the config.
public
setClassBasedOnConfig(array<string|int, mixed> $config) : void
Parameters
- $config : array<string|int, mixed>
apply()
Cast UTC datetime string to JSON datetime string
protected
apply(mixed|null $value) : string|null
Parameters
- $value : mixed|null
Tags
Return values
string|nulldateFormat()
Date format
protected
dateFormat(string|null $value, string $inputTimeZone, string $outputTimezone, string $outputFormat) : string|null
Parameters
- $value : string|null
- $inputTimeZone : string
- $outputTimezone : string
- $outputFormat : string
Return values
string|nullrevert()
Cast JSON datetime string to UTC datetime string
protected
revert(mixed|null $value) : string|null
Parameters
- $value : mixed|null