{"id":21191739,"url":"https://github.com/indieweb/date-formatter-php","last_synced_at":"2025-07-10T03:31:02.628Z","repository":{"id":9369605,"uuid":"11225765","full_name":"indieweb/date-formatter-php","owner":"indieweb","description":"Render dates and date ranges in a human-readable format, including proper microformats-2 markup","archived":false,"fork":false,"pushed_at":"2016-04-05T15:15:44.000Z","size":17,"stargazers_count":18,"open_issues_count":2,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-29T18:59:59.052Z","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":"lord/slate","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indieweb.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":"2013-07-06T23:17:12.000Z","updated_at":"2019-03-10T18:05:38.000Z","dependencies_parsed_at":"2022-08-25T21:40:29.823Z","dependency_job_id":null,"html_url":"https://github.com/indieweb/date-formatter-php","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fdate-formatter-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fdate-formatter-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fdate-formatter-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indieweb%2Fdate-formatter-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indieweb","download_url":"https://codeload.github.com/indieweb/date-formatter-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225311312,"owners_count":17454325,"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-11-20T19:04:46.012Z","updated_at":"2024-11-20T19:04:46.610Z","avatar_url":"https://github.com/indieweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Date Formatter\n==============\n\nRender dates and date ranges in a human-readable format, including proper microformats-2 markup.\n\n[![Build Status](https://travis-ci.org/indieweb/date-formatter-php.svg?branch=master)](http://travis-ci.org/indieweb/date-formatter-php)\n\nUsage\n-----\n\n### Date Range with Time\n\n```php\necho IndieWeb\\DateFormatter::format('2013-10-08T07:00:00-07:00', '2013-10-08T17:00:00-07:00');\n```\n\noutputs\n\n```html\n\u003ctime class=\"dt-start\" datetime=\"2013-10-08T07:00:00-07:00\"\u003e\n  October 8, 2013 from 7:00am\n\u003c/time\u003e\nto\n\u003ctime class=\"dt-end\" datetime=\"2013-10-08T17:00:00-07:00\"\u003e\n  5:00pm (-0700)\n\u003c/time\u003e\n```\n\n(whitespace added for readability)\n\nwhich displays in a browser as\n\n```\nOctober 8, 2013 from 7:00am to 5:00pm (-0700)\n```\n\n### Date Range with No Time\n\n```php\necho IndieWeb\\DateFormatter::format('2013-10-08', '2013-10-11');\n```\n\noutputs\n\n```html\n\u003ctime class=\"dt-start\" datetime=\"2013-10-08\"\u003e\n  October 8\n\u003c/time\u003e\n-\n\u003ctime class=\"dt-end\" datetime=\"2013-10-11\"\u003e\n  11, 2013\n\u003c/time\u003e\n```\n\nwhich displays in a browser as\n\n```\nOctober 8-11, 2013\n```\n\nOther Examples\n--------------\n\nThis example shows how progressively more data is added to the output as the start and end dates have less in common with each other.\n\n```php\nuse IndieWeb\\DateFormatter;\n\necho DateFormatter::format('2013-09-03', '2013-09-08');\n// September 3-8, 2013\n\necho DateFormatter::format('2013-09-28', '2013-10-03');\n// September 28 through October 3, 2013\n\necho DateFormatter::format('2013-12-30', '2014-01-02');\n// December 30, 2013 through January 2, 2014\n```\n\nHere are similar examples when the dates include times as well.\n\n```php\nuse IndieWeb\\DateFormatter;\n\necho DateFormatter::format('2013-10-08T07:00:00-07:00', '2013-10-08T17:00:00-07:00');\n// October 8, 2013 from 7:00am to 5:00pm (-0700)\n\necho DateFormatter::format('2013-10-08T07:00:00-07:00', '2013-10-10T17:00:00-07:00');\n// October 8, 2013 at 7:00am until Oct 10 at 5:00pm (-0700)\n\necho DateFormatter::format('2013-08-31T07:00:00-07:00', '2013-09-01T17:00:00-07:00');\n// August 31, 2013 7:00am until September 1 at 5:00pm (-0700)\n\necho DateFormatter::format('2013-12-31T07:00:00-07:00', '2014-01-01T17:00:00-07:00');\n// December 31, 2013 7:00am until January 1, 2014 5:00pm (-0700)\n```\n\nAlternate Class Names\n---------------------\n\nIf you want the HTML to include Microformats classes other than \"dt-start\" and \"dt-end\", you can pass class names as additional parameters.\n\n```php\necho IndieWeb\\DateFormatter::format('2013-10-08T07:00:00-0700', '2013-10-08T08:50:00-0700', 'dt-departure', 'dt-arrival');\n```\n\n```html\n\u003ctime class=\"dt-departure\" datetime=\"2013-10-08T07:00:00-07:00\"\u003e\n  October 8, 2013 from 7:00am\n\u003c/time\u003e\nto\n\u003ctime class=\"dt-arrival\" datetime=\"2013-10-08T8:50:00-07:00\"\u003e\n  8:50am (-0700)\n\u003c/time\u003e\n```\n\n\n\nTests\n-----\n\nPlease see the [tests](tests/BasicTest.php) for more complete examples of different output formats.\n\n\n\nFuture Enhancements\n-------------------\n\n* Optionally also display the day of the week in date range output\n* Option to use short month names instead of full names\n* Make the parser more tolerant of other input formats\n\nIf you see other input or output formats you would like handled, please open an Issue with a description. Bonus points if you write it as a test case:\n\n```php\n  public function testDescriptionOfWhatYoureTesting() {\n    $this-\u003e_testEquals('Final Text Output', 'start-date', 'end-date');\n  }\n```\n\n\nLicense\n-------\n\nCopyright 2015 by Aaron Parecki\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findieweb%2Fdate-formatter-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findieweb%2Fdate-formatter-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findieweb%2Fdate-formatter-php/lists"}