{"id":16012321,"url":"https://github.com/cornernote/yii-extended-date-time-formatting-behavior","last_synced_at":"2025-03-17T18:17:23.765Z","repository":{"id":19051288,"uuid":"22277464","full_name":"cornernote/yii-extended-date-time-formatting-behavior","owner":"cornernote","description":"ExtendedDateTimeFormattingBehavior adds some methods for extending date\u0026time formatting to CDateFormatter component.","archived":false,"fork":false,"pushed_at":"2014-07-26T03:24:31.000Z","size":144,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T05:23:41.991Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cornernote.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-26T03:19:23.000Z","updated_at":"2014-07-26T03:21:18.000Z","dependencies_parsed_at":"2022-08-21T09:50:18.318Z","dependency_job_id":null,"html_url":"https://github.com/cornernote/yii-extended-date-time-formatting-behavior","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2Fyii-extended-date-time-formatting-behavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2Fyii-extended-date-time-formatting-behavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2Fyii-extended-date-time-formatting-behavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2Fyii-extended-date-time-formatting-behavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cornernote","download_url":"https://codeload.github.com/cornernote/yii-extended-date-time-formatting-behavior/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244085011,"owners_count":20395523,"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":[],"created_at":"2024-10-08T14:02:42.662Z","updated_at":"2025-03-17T18:17:23.744Z","avatar_url":"https://github.com/cornernote.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"**ExtendedDateTimeFormattingBehavior** adds some methods for extending date\u0026time formatting to *CDateFormatter* component.\n\nAvailable formatters:\n\n- `formatDateTimeReadable($timestamp, $dateWidth = 'medium', $timeWidth = 'medium')` formats date\u0026time with pattern **(Today|Yesterday|\u0026lt;date\u0026gt;), \u0026lt;time\u0026gt;**.\n - **$dateWidth** is passed to `CDateFormatter::formatDateTime()` to format **\u0026lt;date\u0026gt;**\n - **$timeWidth** is passed to `CDateFormatter::formatDateTime()` to format **\u0026lt;time\u0026gt;**\n- `formatDateTimeInterval($timestamp, $precisely = false)` formats date\u0026time as a date\u0026time interval with pattern **\u0026lt;metric value\u0026gt; \u0026lt;metric\u0026gt; ago** or more complex **\u0026lt;first metric value\u0026gt; \u0026lt;first metric\u0026gt; and \u0026lt;second metric value\u0026gt; \u0026lt;second metric\u0026gt; ago**\n - **$precisely** is setted to **true**, interval will be composed of two metrics.\n\n**$timestamp** in both formatters can be unix timestamp (integer) or string to pass it to `strtotime()`.\n\n---\nHow to use: attach this behavior to your dateFormatter instance.\n\nFor example, add this in your base controller class (`Controller`) and base console command class (`ConsoleCommand`):\n```php\n    public function init()\n    {\n        parent::init();\n        Yii::app()-\u003edateFormatter-\u003eattachBehavior('ExtendedDateTimeFormatting', 'ext.ExtendedDateTimeFormattingBehavior.ExtendedDateTimeFormattingBehavior');\n    }\n```\n---\n\nExample:\n```php\necho Yii::app()-\u003edateFormatter-\u003eformatDateTimeReadable('yesterday, 20:45:17');\n```\nreturns\n**Yesterday, 8:45:17 PM20**\n```php\necho Yii::app()-\u003edateFormatter-\u003eformatDateTimeInterval('yesterday, 20:45:17', true);\n```\nreturns\n**20 hours and 54 minutes ago**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornernote%2Fyii-extended-date-time-formatting-behavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcornernote%2Fyii-extended-date-time-formatting-behavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornernote%2Fyii-extended-date-time-formatting-behavior/lists"}