{"id":13616918,"url":"https://github.com/KnpLabs/KnpTimeBundle","last_synced_at":"2025-04-14T03:32:00.978Z","repository":{"id":439888,"uuid":"857229","full_name":"KnpLabs/KnpTimeBundle","owner":"KnpLabs","description":"Provides helpers for time manipulation","archived":false,"fork":false,"pushed_at":"2024-06-11T09:39:03.000Z","size":245,"stargazers_count":609,"open_issues_count":15,"forks_count":105,"subscribers_count":32,"default_branch":"main","last_synced_at":"2025-04-10T07:54:11.216Z","etag":null,"topics":["date","php","time"],"latest_commit_sha":null,"homepage":"http://knplabs.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KnpLabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-08-23T17:52:47.000Z","updated_at":"2025-03-29T16:15:07.000Z","dependencies_parsed_at":"2023-01-13T10:18:37.969Z","dependency_job_id":"da93e8a7-fca3-41fc-b854-5e952e98088f","html_url":"https://github.com/KnpLabs/KnpTimeBundle","commit_stats":{"total_commits":213,"total_committers":92,"mean_commits":"2.3152173913043477","dds":0.9061032863849765,"last_synced_commit":"db453621e84ef0b73905d98ff4bd21a1c8396101"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2FKnpTimeBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2FKnpTimeBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2FKnpTimeBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnpLabs%2FKnpTimeBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KnpLabs","download_url":"https://codeload.github.com/KnpLabs/KnpTimeBundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248815600,"owners_count":21165953,"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":["date","php","time"],"created_at":"2024-08-01T20:01:34.773Z","updated_at":"2025-04-14T03:31:55.956Z","avatar_url":"https://github.com/KnpLabs.png","language":"PHP","funding_links":[],"categories":["PHP","Template Engine"],"sub_categories":[],"readme":"# knplabs/knp-time-bundle\n\nFriendly *ago*/*until* dates (\"5 minutes ago\" or \"in 5 minutes\") and *durations* (\"2 mins\")!\n\n```twig\nLast edited: {{ post.updatedAt|time_diff }} \u003c!-- Last edited: 1 week ago --\u003e\n\nEvent date: {{ event.date|time_diff }} \u003c!-- Event date: in two weeks --\u003e\n\nRead time: {{ post.readTimeInSeconds|duration }} \u003c!-- Read time: 2 minutes --\u003e\n\nAge: {{ user.birthdate|age }} \u003c!-- Age: 30 years old --\u003e\n```\n\nWant to see it used in a screencast 🎥? Check out SymfonyCasts: https://symfonycasts.com/screencast/symfony-doctrine/ago\n\nThe formatted date/duration can be translated into any language, and many are supported out of the box.\n\n## Installation\n\nUse Composer to install the library:\n\n```\ncomposer require knplabs/knp-time-bundle\n```\n\nWoo! You did it! Assuming your project uses Symfony Flex, the\nbundle should be configured and ready to go. If not, you\ncan enable `Knp\\Bundle\\TimeBundle\\KnpTimeBundle` manually.\n\n## Usage\n\n### Twig\n\nTime formatting:\n\n```twig\n{{ someDateTimeVariable|time_diff }} {# 2 weeks ago #}\n\n{# |ago is an alias for |time_diff #}\n{{ someDateTimeVariable|ago }} {# 1 second ago #}\n\n{# ... or use the equivalent function: #}\n{{ time_diff(someDateTimeVariable) }} {# in 2 months #}\n```\n\n\u003e **Note**: the `time_diff` filter/function and `ago` alias works fine for dates in the future, too. \n\nDuration formatting:\n\n```twig\n{{ someDurationInSeconds|duration }} {# 2 minutes #}\n```\n\nAge formatting:\n\n```twig\n{# with filter: #}\nAge: {{ user.birthdate|age }} {# Age: 30 years old #}\n\n{# ... or use the equivalent function: #}\nAge: {{ age(user.birthdate) }} {# Age: 30 years old #}\n```\n\n### Service\n\nYou can also format dates and durations in your services/controllers by autowiring/injecting the\n`Knp\\Bundle\\TimeBundle\\DateTimeFormatter` service:\n\n```php\nuse Knp\\Bundle\\TimeBundle\\DateTimeFormatter;\n// ...\n\npublic function yourAction(DateTimeFormatter $dateTimeFormatter)\n{\n    $someDate = new \\DateTimeImmutable('-2 years'); // or $entity-\u003epublishedDate()\n    $toDate = new \\DateTimeImmutable('now');\n\n    $agoTime = $dateTimeFormatter-\u003eformatDiff($someDate, $toDate); // $toDate parameter is optional and defaults to \"now\"\n\n    $readTime = $dateTimeFormatter-\u003eformatDuration(64); // or $entity-\u003ereadTimeInSeconds()\n\n    $ageTime = $dateTimeFormatter-\u003eformatAge($someDate, $toDate); // $toDate parameter is optional and defaults to \"now\"\n\n    return $this-\u003ejson([\n        //  ...\n        'published_at' =\u003e $agoTime, // 2 years ago\n        'read_time' =\u003e $readTime, // 1 minute\n        // ...\n    ]);\n}\n```\n\n## Controlling the Translation Locale\n\nThe bundle will automatically use the current locale when translating\nthe \"time_diff\" (\"ago\") and \"duration\" messages. However, you can override\nthe locale:\n\n```twig\n{{ someDateTimeVariable|time_diff(locale='es') }}\n\n{{ someDurationInSeconds|duration(locale='es') }}\n\n{{ someDateTimeVariable|age(locale='es') }}\n```\n\n## Tests\n\nIf you want to run tests, please check that you have installed dev dependencies.\n\n```bash\n./vendor/bin/phpunit\n```\n\n## Maintainers\n\nAnyone can contribute to this repository (and it's warmly welcomed!). The following\npeople maintain and can merge into this library:\n\n - [@akovalyov](https://github.com/akovalyov)\n - [@weaverryan](https://github.com/weaverryan)\n - [@NicolasNSSM](https://github.com/NicolasNSSM)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKnpLabs%2FKnpTimeBundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKnpLabs%2FKnpTimeBundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKnpLabs%2FKnpTimeBundle/lists"}