{"id":18818716,"url":"https://github.com/chrisharrison/date-validator","last_synced_at":"2025-10-08T15:04:53.200Z","repository":{"id":56952470,"uuid":"206640798","full_name":"chrisharrison/date-validator","owner":"chrisharrison","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-07T15:41:17.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T21:03:54.286Z","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/chrisharrison.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":"2019-09-05T19:23:46.000Z","updated_at":"2019-09-07T15:41:19.000Z","dependencies_parsed_at":"2022-08-21T03:40:21.638Z","dependency_job_id":null,"html_url":"https://github.com/chrisharrison/date-validator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/chrisharrison/date-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisharrison%2Fdate-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisharrison%2Fdate-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisharrison%2Fdate-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisharrison%2Fdate-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisharrison","download_url":"https://codeload.github.com/chrisharrison/date-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisharrison%2Fdate-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278963821,"owners_count":26076544,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-08T00:18:00.371Z","updated_at":"2025-10-08T15:04:53.174Z","avatar_url":"https://github.com/chrisharrison.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# date-validator #\n\n## Installation ##\n\nI've added this to Packagist, so you can use:\n\n```\ncomposer require chrisharrison/date-validator\n```\n\nAlternatively, you can clone the repository and run:\n\n```\ncomposer install\n```\n\n## Running tests ##\n\nRun tests with:\n\n```\nvendor/bin/phpunit\n```\n\n## Usage ##\n\nYou can inject the date validator like this:\n\n```\nfinal class SomeOtherFunctionality\n{\n    private $dateValidator;\n    \n    public function __construct(DateValidator $dateValidator)\n    {\n        $this-\u003edateValidator = $dateValidator;\n    }\n    \n    public function doSomethingWithDate(string $date)\n    {\n        if ($this-\u003edateValidator-\u003evalidate()-\u003eisValid()) {\n            return 'A valid historical date';\n        }\n    }\n}\n```\n\nThis package comes with a default implementation. The `DefaultDateValidator` requires a `Clock` in order for it to compare dates. A `DefaultDateValidator` should be initialised within an IoC container. It can be constructed like this:\n\n```$xslt\n$dateValidator = new DefaultDateValidator(new SystemClock);\n```\n\nThe `validate()` method returns a `DateValidatorResponse` value object with the following methods:\n\n* `isValid(): bool` Whether the date is a valid historical date or not.\n* `getMessage(): DateValidatorResponseMessage` Returns an enum with the following options:\n    * `INVALID_DATE` The input date is not a valid date (e.g. 32/13/1994)\n    * `NOT_A_DATE_IN_THE_PAST` The input date is valid but it's not in the past (e.g. 01/01/3033)\n    * `INVALID_FORMAT` The input is not a date at all (e.g. 'jibberish')\n    * If the date is valid then the message is a null version of `DateValidatorResponseMessage`\n    \nThis package also [provides a singleton](src/Singleton) which can be used like this:\n```\nuse ChrisHarrison\\DateValidator\\Singleton\\DateValidator;\n\nDateValidator::validateHistoricalDate('03/12/1999');\n```\n\nThe singleton uses a DefaultDateValidator internally and `validateHistoricalDate()` works the same way as above.\n\n## My strategy ##\n\nYou can see the way that I approached this task my looking at my commit history.\n\n## Note on really historical dates ##\n\nThe solution I've written handles dates back to the year 1 CE. It doesn't handle dates BCE. And bizarrely thinks that there is a year zero. If I was to devote more time to this - and there was a business case for it - I'd investigate that. [OK I couldn't resist looking it up. It seems that PHP is using some implementation of ISO 8601 and not the Gregorian calendar]\n\n## Note on PHP date formats ##\n\nThe stipulation that the input date format should be `DD/MM/YYYY` reminded me of an interesting quirk of certain PHP functions which I discussed in a [Stackoverflow answer](https://stackoverflow.com/questions/2444820/how-to-make-strtotime-parse-dates-in-australian-i-e-uk-format-dd-mm-yyyy/5619817#5619817) many years ago. Just a mildly interesting titbit 😄","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisharrison%2Fdate-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisharrison%2Fdate-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisharrison%2Fdate-validator/lists"}