DateTime
class DateTime extends DateTime implements DateTimeInterface (View source)
An extension of PHP's DateTime class to provide dirty flagging and easier formatting options.
All date and datetime fields from your database will be created as instances of this class.
Example of formatting and changing the default format:
$now = new ActiveRecord\DateTime('2010-01-02 03:04:05');
ActiveRecord\DateTime::$DEFAULT_FORMAT = 'short';
echo $now->format(); # 02 Jan 03:04 echo $now->format('atom'); # 2010-01-02T03:04:05-05:00 echo $now->format('Y-m-d'); # 2010-01-02
__toString() uses the default formatter
echo (string)$now; # 02 Jan 03:04
You can also add your own pre-defined friendly formatters:
ActiveRecord\DateTime::$FORMATS['awesome_format'] = 'H:i:s m/d/Y';
echo $now->format('awesome_format') # 03:04:05 01/02/2010
Properties
static | $DEFAULT_FORMAT | Default format used for format() and __toString() | |
static | $FORMATS | Pre-defined format strings. |
Methods
Indicates this object is an attribute of the specified model, with the given attribute name.
Formats the DateTime to the specified format.
Returns the format string.
This needs to be overriden so it returns an instance of this class instead of PHP's \DateTime.
No description
Handle PHP object clone
.
No description
No description
No description
No description
No description
No description
No description
No description
Details
at line 67
void
attribute_of(Model $model, string $attribute_name)
Indicates this object is an attribute of the specified model, with the given attribute name.
at line 87
format($format = null)
Formats the DateTime to the specified format.
$datetime->format(); # uses the format defined in DateTime::$DEFAULT_FORMAT
$datetime->format('short'); # d M H:i
$datetime->format('Y-m-d'); # Y-m-d
at line 102
static string
get_format(string $format = null)
Returns the format string.
If $format is a pre-defined format in $FORMATS it will return that otherwise it will assume $format is a format string itself.
at line 120
static
createFromFormat($format, $time, $tz = null)
This needs to be overriden so it returns an instance of this class instead of PHP's \DateTime.
See http://php.net/manual/en/datetime.createfromformat.php
at line 131
__toString()
at line 144
void
__clone()
Handle PHP object clone
.
This makes sure that the object doesn't still flag an attached model as dirty after cloning the DateTime object and making modifications to it.