{"id":16012312,"url":"https://github.com/cornernote/extendeddatetimeformattingbehavior","last_synced_at":"2025-03-17T18:17:35.344Z","repository":{"id":16236397,"uuid":"18983995","full_name":"cornernote/ExtendedDateTimeFormattingBehavior","owner":"cornernote","description":"[Yii] Behavior for CDateFormater that adds some methods for extending date\u0026time formatting.","archived":false,"fork":false,"pushed_at":"2014-04-21T23:53:57.000Z","size":147,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T05:23:51.189Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"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-04-21T06:10:57.000Z","updated_at":"2014-06-02T13:32:37.000Z","dependencies_parsed_at":"2022-09-14T03:22:17.851Z","dependency_job_id":null,"html_url":"https://github.com/cornernote/ExtendedDateTimeFormattingBehavior","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%2FExtendedDateTimeFormattingBehavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2FExtendedDateTimeFormattingBehavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2FExtendedDateTimeFormattingBehavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornernote%2FExtendedDateTimeFormattingBehavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cornernote","download_url":"https://codeload.github.com/cornernote/ExtendedDateTimeFormattingBehavior/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:40.749Z","updated_at":"2025-03-17T18:17:35.322Z","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`):\n```php\n\tpublic function beforeAction($action) {\n\t\tYii::import('ext.ExtendedDateTimeFormattingBehavior.ExtendedDateTimeFormattingBehavior');\n\t\tYii::app()-\u003edateFormatter-\u003eattachBehavior('ExtendedDateTimeFormatting', new ExtendedDateTimeFormattingBehavior());\n\t\treturn parent::beforeAction($action);\n\t}\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%2Fextendeddatetimeformattingbehavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcornernote%2Fextendeddatetimeformattingbehavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornernote%2Fextendeddatetimeformattingbehavior/lists"}