{"id":15525360,"url":"https://github.com/ghostwriter/uuid","last_synced_at":"2025-04-23T08:52:22.741Z","repository":{"id":249470752,"uuid":"831582654","full_name":"ghostwriter/uuid","owner":"ghostwriter","description":"Provides sortable Universally Unique Identifiers (UUID) using Unix timestamp.","archived":false,"fork":false,"pushed_at":"2025-04-22T00:54:13.000Z","size":339,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"1.0.x","last_synced_at":"2025-04-22T01:31:51.707Z","etag":null,"topics":["ghostwriter","uuid","uuid-7"],"latest_commit_sha":null,"homepage":"https://github.com/ghostwriter/uuid","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghostwriter.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["ghostwriter"]}},"created_at":"2024-07-21T02:06:47.000Z","updated_at":"2025-04-22T00:54:15.000Z","dependencies_parsed_at":"2024-07-21T06:05:09.044Z","dependency_job_id":"0d8e907c-b260-4e85-97d2-7a10419d3215","html_url":"https://github.com/ghostwriter/uuid","commit_stats":null,"previous_names":["ghostwriter/uuid"],"tags_count":4,"template":false,"template_full_name":"ghostwriter/wip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostwriter%2Fuuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostwriter%2Fuuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostwriter%2Fuuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostwriter%2Fuuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghostwriter","download_url":"https://codeload.github.com/ghostwriter/uuid/tar.gz/refs/heads/1.0.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250162783,"owners_count":21385113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ghostwriter","uuid","uuid-7"],"created_at":"2024-10-02T10:57:04.839Z","updated_at":"2025-04-23T08:52:22.735Z","avatar_url":"https://github.com/ghostwriter.png","language":"PHP","funding_links":["https://github.com/sponsors/ghostwriter"],"categories":[],"sub_categories":[],"readme":"# Uuid\n\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/ghostwriter?label=Sponsor+@ghostwriter/uuid\u0026logo=GitHub+Sponsors)](https://github.com/sponsors/ghostwriter)\n[![Automation](https://github.com/ghostwriter/uuid/actions/workflows/automation.yml/badge.svg)](https://github.com/ghostwriter/uuid/actions/workflows/automation.yml)\n[![Supported PHP Version](https://badgen.net/packagist/php/ghostwriter/uuid?color=8892bf)](https://www.php.net/supported-versions)\n[![Downloads](https://badgen.net/packagist/dt/ghostwriter/uuid?color=blue)](https://packagist.org/packages/ghostwriter/uuid)\n\nVersion 7 UUIDs using a Unix timestamp for PHP\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require ghostwriter/uuid\n```\n\n### Star ⭐️ this repo if you find it useful\n\nYou can also star (🌟) this repo to find it easier later.\n\n## Usage\n\nInitialize a new Uuid instance with a given UUID string\n\n```php\nuse Ghostwriter\\Uuid\\Uuid;\n\n$uuid = new Uuid('0000669c-8deb-7fe7-b9cc-692b216999a3');\n// or\n$uuid = Uuid::fromString('0000669c-8deb-7fe7-b9cc-692b216999a3');\n\necho $uuid-\u003etoString(); // 0000669c-8deb-7fe7-b9cc-692b216999a3\n```\n\nGenerate a new UUID\n\n```php\necho Uuid::new()-\u003etoString(); // 0000669c-8f99-711e-9ed0-72a35c3b6fb3\n```\n\nGenerate a new UUID with a specific timestamp\n\n```php\necho Uuid::new(new DateTimeImmutable())-\u003etoString(); // 0000669c-8faf-7e4b-9ed9-45c4c2b27f07\n```\n\nCompare and Sort UUIDs based on their timestamp ( `0: equal`, `1: older`, `-1: newer`)\n\n```php\n$uuidLastYear = Uuid::new(new DateTimeImmutable('-1 year'));\n$uuidLastMonth = Uuid::new(new DateTimeImmutable('-1 month'));\n$uuidLastWeek = Uuid::new(new DateTimeImmutable('-1 week'));\n\n// LastYear comparisons\n// 0: LastYear is the same as LastYear\nassert(0 === $uuidLastYear-\u003ecompare($uuidLastYear));\n// -1: LastMonth is newer than LastYear\nassert(-1 === $uuidLastYear-\u003ecompare($uuidLastMonth));\n// -1: LastWeek is newer than LastYear\nassert(-1 === $uuidLastYear-\u003ecompare($uuidLastWeek));\n\n// LastMonth comparisons\n// 1: LastYear is older than LastMonth\nassert(1 === $uuidLastMonth-\u003ecompare($uuidLastYear));\n// 0: LastMonth is the same as LastMonth\nassert(0 === $uuidLastMonth-\u003ecompare($uuidLastMonth));\n// -1: LastWeek is newer than LastMonth\nassert(-1 === $uuidLastMonth-\u003ecompare($uuidLastWeek));\n\n// LastWeek comparisons\n// 1: LastYear is older than LastWeek\nassert(1 === $uuidLastWeek-\u003ecompare($uuidLastYear));\n// 1: LastMonth is older than LastWeek\nassert(1 === $uuidLastWeek-\u003ecompare($uuidLastMonth));\n// 0: LastWeek is the same as LastWeek\nassert(0 === $uuidLastWeek-\u003ecompare($uuidLastWeek));\n\n/** @var array{0:UuidInterface,1:UuidInterface,2:UuidInterface,3:UuidInterface} $uuids */\n$uuids = [$uuidLastWeek, $uuidLastYear, $uuidLastMonth];\n\nusort($uuids, static fn (UuidInterface $left, UuidInterface $right): int =\u003e $left-\u003ecompare($right));\n\n// First: LastYear (oldest)\nassert($uuidLastYear === $uuids[0]);\n// Second: LastMonth\nassert($uuidLastMonth === $uuids[1]);\n// Third: LastWeek\nassert($uuidLastWeek === $uuids[2]);\n```\n\n### Credits\n\n- [Nathanael Esayeas](https://github.com/ghostwriter)\n- [All Contributors](https://github.com/ghostwriter/uuid/contributors)\n\n### Changelog\n\nPlease see [CHANGELOG.md](./CHANGELOG.md) for more information on what has changed recently.\n\n### License\n\nPlease see [LICENSE](./LICENSE) for more information on the license that applies to this project.\n\n### Security\n\nPlease see [SECURITY.md](./SECURITY.md) for more information on security disclosure process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghostwriter%2Fuuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghostwriter%2Fuuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghostwriter%2Fuuid/lists"}