{"id":13824774,"url":"https://github.com/nojimage/cakephp-time-interval","last_synced_at":"2025-12-30T18:42:15.161Z","repository":{"id":56977082,"uuid":"182065905","full_name":"nojimage/cakephp-time-interval","owner":"nojimage","description":"Time interval custom type for CakePHP","archived":false,"fork":false,"pushed_at":"2025-06-09T11:36:57.000Z","size":52,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"cake5","last_synced_at":"2025-06-09T12:32:29.536Z","etag":null,"topics":["cakephp","cakephp-plugin","database","interval","time"],"latest_commit_sha":null,"homepage":"","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/nojimage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2019-04-18T10:17:14.000Z","updated_at":"2025-06-09T11:34:21.000Z","dependencies_parsed_at":"2024-05-01T05:31:25.226Z","dependency_job_id":"f2e38938-37e6-4729-bdfc-6e860a66f739","html_url":"https://github.com/nojimage/cakephp-time-interval","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"74f49556b9c0e4bc5a9e32b4e3094e0f98d01c8a"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/nojimage/cakephp-time-interval","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nojimage%2Fcakephp-time-interval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nojimage%2Fcakephp-time-interval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nojimage%2Fcakephp-time-interval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nojimage%2Fcakephp-time-interval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nojimage","download_url":"https://codeload.github.com/nojimage/cakephp-time-interval/tar.gz/refs/heads/cake5","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nojimage%2Fcakephp-time-interval/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264334177,"owners_count":23592374,"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":["cakephp","cakephp-plugin","database","interval","time"],"created_at":"2024-08-04T09:01:09.080Z","updated_at":"2025-12-30T18:42:15.111Z","avatar_url":"https://github.com/nojimage.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# TimeInterval plugin for CakePHP\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"LICENSE.txt\" target=\"_blank\"\u003e\n        \u003cimg alt=\"Software License\" src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/nojimage/cakephp-time-interval/actions\" target=\"_blank\"\u003e\n        \u003cimg alt=\"Build Status\" src=\"https://img.shields.io/github/actions/workflow/status/nojimage/cakephp-time-interval/ci.yml?style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/nojimage/cakephp-time-interval\" target=\"_blank\"\u003e\n        \u003cimg alt=\"Codecov\" src=\"https://img.shields.io/codecov/c/github/nojimage/cakephp-time-interval.svg?style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/elstc/cakephp-time-interval\" target=\"_blank\"\u003e\n        \u003cimg alt=\"Latest Stable Version\" src=\"https://img.shields.io/packagist/v/elstc/cakephp-time-interval.svg?style=flat-square\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nThis plugin provides `time_interval` custom type for MySQL's `TIME`, Postgres's `INTERVAL`,\n and provides `time_interval_int` custom type for seconds as `INTEGER`.\nThis is a custom type to represent intervals, which CakePHP can treat as a `TimeInterval` object that inherits from `DateInterval`.\n\n## Version Map\n\n| CakePHP Version | Plugin Version | Branch         |\n|-----------------|----------------|----------------|\n| 5.x             | 3.x            | cake5          |\n| 4.x             | 2.x            | cake4          |\n| 3.x             | 0.3.x          | cake3          |\n\n## Installation\n\nYou can install this plugin into your CakePHP application using [composer](http://getcomposer.org).\n\nThe recommended way to install composer packages is:\n\n```\ncomposer require elstc/cakephp-time-interval\n```\n\n### Load plugin\n\nLoad the plugin by adding the following statement in your project's `src/Application.php`:\n\n```\n$this-\u003eaddPlugin('Elastic/TimeInterval');\n```\n\n## Usage\n\n### Add column definitions to Table class\n\n```php\nuse Cake\\Database\\Schema\\TableSchema;\n\nclass WorkTimesTable extends Table\n{\n    protected function _initializeSchema(TableSchema $schema)\n    {\n        parent::_initializeSchema($schema);\n\n        $schema-\u003esetColumnType('duration', 'time_interval');\n\n        // If your column type is seconds as INTEGER, Use `time_interval_int` instead.\n        $schema-\u003esetColumnType('duration_sec', 'time_interval_int');\n\n        return $schema;\n    }\n}\n```\n\n### Add column validation to Table class\n\nUse `timeInterval` rule instead of `time`.\nThe `timeInterval` rule is in the `timeInterval` validation provider. \n\n```php\nuse Cake\\Validation\\Validator;\nuse Elastic\\TimeInterval\\Validation\\TimeIntervalValidation;\n\nclass WorkTimesTable extends Table\n{\n    public function validationDefault(Validator $validator)\n    {\n        // ...\n        $validator-\u003eadd('duration', 'timeInterval', [\n            'rule' =\u003e 'timeInterval',\n            'provider' =\u003e 'timeInterval',\n        ]);\n\n        return $validator;\n    }\n}\n```\n\n### Adding a mutator to the Entity class is useful\n\n```php\nuse Cake\\Database\\Type;\n\nclass WorkTime extends Entity\n{\n    protected function _setDuration($value)\n    {\n        // convert to TimeInterval\n        return Type::build('time_interval')-\u003emarshal($value);\n    }\n}\n\n$workTime-\u003eduration = '00:15:00';\n$workTime-\u003eduration = ($startTime)-\u003ediff($endTime); // $startTime, $endTime are DateTime objects.\n$workTime-\u003eduration = 3600; // as seconds\n```\n\n## NOTE\n\n### MySQL TIME column limitation\n\n[MySQL :: MySQL 8.0 Reference Manual :: 13.2.3 The TIME Type](https://dev.mysql.com/doc/refman/8.0/en/time.html)\n\n    By default, values that lie outside the TIME range but are otherwise valid are clipped to the closest endpoint of the range. For example,\n    '-850:00:00' and '850:00:00' are converted to '-838:59:59' and '838:59:59'. Invalid TIME values are converted to '00:00:00'.\n    Note that because '00:00:00' is itself a valid TIME value, there is no way to tell, from a value of '00:00:00' stored in a table,\n    whether the original value was specified as '00:00:00' or whether it was invalid.\n\n### DateInterval / TimeInterval constructed with date parts will have incorrect time interpretation\n\nIf you initialize DateInterval with date parts, time will not be interpreted correctly.\n\n```php\n$workTime-\u003eduration = new DateInterval('PT75H4M5S'); // OK\n$workTime-\u003eduration = new DateInterval('P1M2DT3H4M5S'); // can't get expected time\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnojimage%2Fcakephp-time-interval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnojimage%2Fcakephp-time-interval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnojimage%2Fcakephp-time-interval/lists"}