I'm extending DateTime
do add some useful methods and constants.
When using new
to create a new object everything is fine but when using the static method createFromFormat
it always returns the original DateTime
object and of course none of the child methods are available.
I am using the following code to circumvent this issue. Is this the best approach?
namespace NoiseLabs\DateTime;
class DateTime extends \DateTime
{
static public function createFromFormat($format, $time)
{
$ext_dt = new self();
$ext_dt->setTimestamp(parent::createFromFormat($format, time)->getTimestamp());
return $ext_dt;
}
}