DBDateTime
extends SerializableDateTime
in package
DateTime serializer for database operations.
Formats DateTime as 'Y-m-d H:i:s' (MySQL DATETIME format) for seamless serialization and deserialization with database timestamp columns.
Used for created_at and updated_at fields in Model instances.
Tags
Table of Contents
Methods
- fromDT() : static
- Create a SerializableDateTime from an existing DateTime instance.
- fromString() : static
- jsonSerialize() : string
- Serialize this DateTime for JSON encoding.
- marshall() : string
- Convert this DateTime to a formatted string.
- parse() : static
- Parse a formatted date string into this DateTime.
- getFormat() : string
- Get the DateTime format for database serialization.
Methods
fromDT()
Create a SerializableDateTime from an existing DateTime instance.
public
static fromDT(DateTime $dt) : static
Convenient factory method for converting existing DateTime objects.
Parameters
- $dt : DateTime
-
The source DateTime.
Return values
static —A new instance with the same timestamp as $dt.
fromString()
public
static fromString(string $data) : static
Parameters
- $data : string
Return values
staticjsonSerialize()
Serialize this DateTime for JSON encoding.
public
jsonSerialize() : string
Implements JsonSerializable to enable json_encode() on Obj instances containing DateTime fields.
Return values
string —The formatted date/time string (via marshall()).
marshall()
Convert this DateTime to a formatted string.
public
marshall() : string
Called during serialization when this DateTime appears in an Obj field.
Return values
string —The formatted date/time string.
parse()
Parse a formatted date string into this DateTime.
public
parse(mixed $data) : static
Called during deserialization when a string is provided for a DateTime field.
Parameters
- $data : mixed
-
The date string to parse (should match getFormat()).
Tags
Return values
static —This instance, updated with the parsed timestamp.
getFormat()
Get the DateTime format for database serialization.
protected
static getFormat() : string
Return values
string —MySQL DATETIME format 'Y-m-d H:i:s'.