tuupola/ulid

Universally Unique Lexicographically Sortable Identifier

0.1.0 2018-04-15 17:12 UTC

README

This library implements the Universally Unique Lexicographically Sortable Identifier from Alizain Feerasta.

Latest Version Software License Build Status Coverage

Install

Install with composer.

$ composer require tuupola/ulid

Usage

use Tuupola\Ulid;

$ulid = new Ulid;

print $ulid; /* 0001DD70YKYBES1P98DHWKTWZW */

//$ulid = ulid::fromString("0o5Fs0EELR0fUjHjbCnEtdUwQe3");

print $ulid->timestamp(); /* 1523811283 */
print bin2hex($ulid->payload()); /* f2dd90d9286c793d73fc */

$datetime = (new \DateTimeImmutable)
    ->setTimestamp($ulid->unixtime())
    ->setTimeZone(new \DateTimeZone("UTC"));

print $datetime->format("Y-m-d H:i:s"); /* 2018-04-15 16:54:43 */

Testing

You can run tests either manually or automatically on every code change. Automatic tests require entr to work.

$ composer test
$ brew install entr
$ composer watch

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email tuupola@appelsiini.net instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.