My Profile Photo

Coder Spirit

I'm Andrés Correa Casablanca. I work as a software engineer, but I have a scientist in my heart. I love mathematics, algorithms, AI, and machine learning.

Dealing with precise timestamps in PHP

PHP does not offer any native class to implement timestamps with milliseconds or microseconds precision, the only “native” way to do it is working with the weird microtime function and/or the \MongoDate class (available through the mongo extension).

Using the \DateTime class is not enough, because it only can offer seconds precision, and using the \MongoDate class isn’t a good idea if you aren’t using MongoDB or if you care about coupling. In fact, the mongo extension will be deprecated in a few months in favour of a new extension that is in active development right now.

Because this, I’ve developed two Composer packages to allow using type hinting without increasing coupling and with less abstraction leaks:

Is my intention to modify the PHP-Jiffy library at the same time of the new MongoDB’s extension release, so it will be very useful for people who likes moving fast to new software versions.

comments powered by Disqus