vascowhite / datefactory
A factory class for DateTime objects.
Requires (Dev)
This package is not auto-updated.
Last update: 2024-12-21 17:33:03 UTC
README
#DateFactory
A factory for \DateTime
objects with checks that the date string supplied matches the format supplied.
##Installation Install using composer, add the following to composer.json:-
"require": { "vascowhite/datefactory": "v1.1.x" }
##Why
Because \DateTime::createFromFormat()
does stupid things and I needed a way of doing server side validation on user supplied dates.
##DateFactory There is just one public method:
####DateFactory::getDate() Signature:-
DateTime DateFactory::getDate(String $date, String $format, [String $timeZone])
Arguments
$date
is a string representing a date/time, e.g. '2014-14 14:12:10'.
$format
Format string. Available formats are any available for \DateTime::createFromFormat()
.
$timeZone
Optional. A valid Time Zone identifier from this list.
Example
$dateTime = DateFactory::getDate('2014-12-25 12:00:00', 'Y-m-d H:i:s', 'Europe/London');
Return
Returns a DateTime
object or false on failure.