{"id":18546773,"url":"https://github.com/nabeghe/dati-php","last_synced_at":"2025-10-11T14:04:10.402Z","repository":{"id":258712713,"uuid":"875404222","full_name":"nabeghe/dati-php","owner":"nabeghe","description":"A simple DateTime helper for common stuff.","archived":false,"fork":false,"pushed_at":"2025-08-13T17:38:04.000Z","size":24,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-11T14:04:07.040Z","etag":null,"topics":["date","datetime","php","php-date","php-datetime","php-helper","php-library","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/nabeghe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-19T22:06:58.000Z","updated_at":"2025-08-13T17:36:45.000Z","dependencies_parsed_at":"2024-11-06T20:33:03.433Z","dependency_job_id":"8d98ab9e-01ff-47cf-9eff-c7884380a6ca","html_url":"https://github.com/nabeghe/dati-php","commit_stats":null,"previous_names":["nabeghe/dati-php"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/nabeghe/dati-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Fdati-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Fdati-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Fdati-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Fdati-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nabeghe","download_url":"https://codeload.github.com/nabeghe/dati-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Fdati-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007481,"owners_count":26084313,"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-11T02:00:06.511Z","response_time":55,"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":["date","datetime","php","php-date","php-datetime","php-helper","php-library","time"],"created_at":"2024-11-06T20:26:54.758Z","updated_at":"2025-10-11T14:04:10.397Z","avatar_url":"https://github.com/nabeghe.png","language":"PHP","readme":"# Dati (Date Time Helper for PHP)\n\n\u003e A simple DateTime helper for common stuff.\n\nConverting dates between the Gregorian and Jalali (Shamsi/Persian) calendars and vice versa,\nChecking the validity of Gregorian and Jalali dates,\nspam detection based on datetime sequences,\ndetecting datetime formats,\ncalculating the difference between two datetimes in a preferred unit or the largest possible unit,\nremaining time between two datetimes based on validity,\nchecking for leap years in both Gregorian and Jalali calendars,\nadding a value to a datetime,\nconverting timezones to a desired or local one,\nmonth names, month lengths, current time, and so on!\n\n\u003cb style=\"color: red\"\u003eNotice:\u003c/b\u003e To convert Gregorian dates to Jalali and vice versa, the `intl` extension must be enabled in PHP.\n\n## 🫡 Usage\n\n### 🚀 Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require nabeghe/dati\n```\n\n### Dati Class\n\n#### Example 1:\n\n```php\nuse Nabeghe\\Dati\\Dati;\n\n# Convert Gregorian to Jalali\necho \"1995-11-20 00:00:00 To Jalali = \".Dati::toJalali('1995-11-20 00:00:00').\"\\n\"; // 1374-08-29 00:00:00\n\n# Convert Jalali to Gregorian\necho \"1374-08-29 00:00:00 To Jalali = \".Dati::fromJalali('1374-08-29 00:00:00').\"\\n\"; // 1995-11-20 00:00:00\n\n# Detect Format:\necho '1995-11-20 00:00:00 Format = '.Dati::detectFormat('1995-11-20 00:00:00').\"\\n\"; // Y-m-d H:i:s\n\n# Difference between two datetimes:\necho 'Diff between 1995-11-20 00:00:00 \u0026 1995-11-20 00:00:01 = '.Dati::diff('1995-11-20 00:00:00', '1995-11-20 00:00:01').\"\\n\"; // 1 seconds\necho 'Diff between 1995-11-20 00:00:00 \u0026 1995-11-31 00:00:00 = '.Dati::diff('1995-11-20 00:00:00', '1995-11-31 00:00:00', 'days').\"\\n\"; // 11 days\necho 'Diff between 1995-11-20 00:00:00 \u0026 1995-11-31 12:00:00 = '.Dati::diff('1995-11-20 00:00:00', '1995-11-31 12:00:00', 'days').\"\\n\"; // 11.5 days\necho 'Diff between 1995-11-20 00:00:00 \u0026 2024-10-19 22:58:00 = '.((int) Dati::diff('1995-11-20 00:00:00', '2024-10-19 22:58:00', 'years')).\"\\n\"; // 28 years\n\n# Difference between two dates based on largest possible unit:\necho \"How Long Ago From 2024-10-19 00:00:00 to 2025-10-19 00:00:00 = \".json_encode(Dati::howLongAgo('2024-10-19 00:00:00', '2025-10-19 00:00:00')).\"\\n\";\n// Output: {\"unit\":\"years\",\"value\":1,\"diff\":31536000}\n\n# Check leap Year\necho 'Year 2024 gregorian '.Dati::isLeap(2024) ? \"is leap\\n\" : \"is not leap\\n\";\necho 'Year 1403 Jalali '.Dati::isLeap(1403, true) ? \"is leap\\n\" : \"is not leap\\n\";\n\n# Join a value to datetime:\necho 'Join 1 secoonds to 1995-11-20 00:00:00 = '.Dati::join('+1', 'seconds', '1995-11-20 00:00:00').\"\\n\"; // 1995-11-20 00:00:0\necho 'Join 2 weeks to 1995-11-20 00:00:00 = '.Dati::join('+2', 'weeks', '1995-11-20 00:00:00').\"\\n\"; // 1995-12-04 00:00:00\necho 'Join 3 months to 1995-11-20 00:00:00 = '.Dati::join('3', 'month', '1995-11-20 00:00:00').\"\\n\"; // 1996-02-20 00:00:00\n\n# Remaining value until expiration! Suitable for things like premium subscriptions that have validity:\necho 'Remaining minutes to reach 2024-10-20 00:00:00 since 2024-10-19 23:00:00 = '.Dati::remaining('2024-10-19 23:00:00', '2024-10-20 00:00:00', 60, 'minutes').\"\\n\"; // 0\necho 'Remaining minutes to reach 2024-10-20 00:00:00 since 2024-10-19 23:00:00 '.((int) Dati::remaining('2024-10-19 23:00:00', '2024-10-20 00:00:00', 120, 'minutes')).\"\\n\"; // 60\n\necho 'Parsed Unit `1s` = '.json_encode(Dati::parseUnit('1s')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `1S` = '.json_encode(Dati::parseUnit('1S')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `1sec` = '.json_encode(Dati::parseUnit('1sec')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `1Sec` = '.json_encode(Dati::parseUnit('1Sec')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `1second` = '.json_encode(Dati::parseUnit('1second')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `1Second` = '.json_encode(Dati::parseUnit('1Second')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `1seconds` = '.json_encode(Dati::parseUnit('1seconds')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `1Seconds` = '.json_encode(Dati::parseUnit('1Seconds')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `1 s` = '.json_encode(Dati::parseUnit('1 s')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit ` 1 s ` = '.json_encode(Dati::parseUnit('1 s ')).\"\\n\"; // [1,\"seconds\"]\necho 'Parsed Unit `2m` = '.json_encode(Dati::parseUnit('2m')).\"\\n\"; // [2,\"minutes\"]\necho 'Parsed Unit `3h` = '.json_encode(Dati::parseUnit('3h')).\"\\n\"; // [3,\"hours\"]\necho 'Parsed Unit `4d` = '.json_encode(Dati::parseUnit('4d')).\"\\n\"; // [4,\"days\"]\necho 'Parsed Unit `5w` = '.json_encode(Dati::parseUnit('5w')).\"\\n\"; // [5,\"weeks\"]\necho 'Parsed Unit `6M` = '.json_encode(Dati::parseUnit('6M')).\"\\n\"; // [6,\"months\"]\necho 'Parsed Unit `7y` = '.json_encode(Dati::parseUnit('7y')).\"\\n\"; // [7,\"years\"]\n```\n\n#### Example 2 - Check Spam:\n\nSometimes it is necessary to check the datetime of an action to determine if it is spam.\nFor example, reviewing the last ten datetimes of messages or tickets that have been sent.\n\n```php\n// Syntax:\nDiff::checkSpam(array $datetimes, int $offset = 1, int $limit = 3, $strict = false)\n```\n\n- `datetimes`: Sequence of datetimes.\n- `offset`: If the difference between two consecutive datetimes is equal to or less than this amount, a warning indicating potential spam has occurred.\n- `limit`: Receiving how many warning indicates spam?\n- `strict`: If it's not strict, if no warning is received between two consecutive datetimes, one of the previous warnings will be reduced.\n\n```php\nuse Nabeghe\\Dati\\Dati;\n\nif (Dati::checkSpam([\n    '2024-10-19 22:46:01',\n    '2024-10-19 22:46:02',\n    '2024-10-19 22:46:03',\n    '2024-10-19 22:46:04',\n])) {\n    echo \"Spam 1\\n\";\n}\n\nif (Dati::checkSpam([\n    '2024-10-19 22:46:01',\n    '2024-10-19 22:46:01',\n    '2024-10-19 22:46:01',\n    '2024-10-19 22:46:01',\n])) {\n    echo \"Spam 2\\n\";\n}\n\nif (!Dati::checkSpam([\n    '2024-10-19 22:46:01',\n    '2024-10-19 22:46:02',\n    '2024-10-19 22:46:03',\n])) {\n    echo \"Not Spam 3\\n\";\n}\n\nif (!Dati::checkSpam([\n    '2024-10-19 22:46:01',\n    '2024-10-19 22:46:03',\n    '2024-10-19 22:46:03',\n    '2024-10-19 22:46:03',\n])) {\n    echo \"Not Spam 4\\n\";\n}\n```\n\n### Months Class\n\nAccess to the names and lengths of the months in the Gregorian, Jalali, and lunar calendars.\n\n```php\nuse Nabeghe\\Dati\\Months;\n\necho \"Month Length 2024/11: \" . Months::length(2024, 11) . \"\\n\"; // 30\necho \"Month Length 2024/12: \" . Months::length(2024, 12) . \"\\n\"; // 31\necho \"Month Length 1402/12 (Jalali): \" . Months::length(1402, 12,  'jalali') . \"\\n\"; // 29\necho \"Month Length 1403/12 (Jalali): \" . Months::length(1403, 12,  'jalali') . \"\\n\"; // 30\necho \"Month Length 1404/12 (Jalali): \" . Months::length(1404, 12,  'jalali') . \"\\n\"; // 29\n\necho \"Month Name 11: \" . Months::name(11, 'gregorian', true) . \"\\n\"; // November\necho \"Month Name 11: \" . Months::name(11, 'gregorian', false) . \"\\n\"; // نوامبر\n```\n\n### Now Class\n\nAccess to the current datetime.\n\n#### Example 1:\n\n```php\nuse Nabeghe\\Dati\\Now;\n\necho \"Now (GMT): \" . Now::datetime() . \"\\n\";\necho \"Now (GMT): \" . Now::datetime() . \"\\n\"; // The output will be the same as before. The time has been cached.\necho \"Now (Local): \" . Now::datetimeNew() . \"\\n\";\necho \"Now (Local): \" . Now::datetimeLocal() . \"\\n\";\necho \"Now (Local): \" . Now::datetimeLocal() . \"\\n\"; // The output will be the same as before. The time has been cached.\necho \"Now (Local): \" . Now::datetimeLocalNew() . \"\\n\";\n```\n\n#### Example 2 - Initialization with previous values\n\nIf it is necessary to use a previously obtained datetime.\n\n```php\nuse Nabeghe\\Dati\\Now;\n\nNow::init('1995-11-20 00:00:00', '1995-11-20 13:14:00');\n\necho \"Now (GMT): \" . Now::datetime() . \"\\n\"; // 1995-11-20 00:00:00\necho \"Now (Local): \" . Now::datetimeLocal() . \"\\n\"; // 1995-11-20 13:14:00\n```\n\n## 📖 License\n\nLicensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnabeghe%2Fdati-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnabeghe%2Fdati-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnabeghe%2Fdati-php/lists"}