{"id":18656251,"url":"https://github.com/bayfrontmedia/php-time-helpers","last_synced_at":"2025-05-12T14:15:52.144Z","repository":{"id":62492265,"uuid":"282997517","full_name":"bayfrontmedia/php-time-helpers","owner":"bayfrontmedia","description":"Helper class to provide useful time related functions.","archived":false,"fork":false,"pushed_at":"2025-04-11T02:16:40.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T03:06:53.753Z","etag":null,"topics":["date","datetime","elapsed","human","php","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/bayfrontmedia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null}},"created_at":"2020-07-27T19:36:19.000Z","updated_at":"2025-04-11T02:16:12.000Z","dependencies_parsed_at":"2023-02-14T19:50:36.028Z","dependency_job_id":null,"html_url":"https://github.com/bayfrontmedia/php-time-helpers","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-time-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-time-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-time-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-time-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bayfrontmedia","download_url":"https://codeload.github.com/bayfrontmedia/php-time-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253749428,"owners_count":21958120,"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":["date","datetime","elapsed","human","php","time"],"created_at":"2024-11-07T07:22:32.314Z","updated_at":"2025-05-12T14:15:52.134Z","avatar_url":"https://github.com/bayfrontmedia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## PHP time helpers\n\nHelper class to provide useful time related functions.\n\n- [License](#license)\n- [Author](#author)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n\n## Author\n\n\u003cimg src=\"https://cdn1.onbayfront.com/bfm/brand/bfm-logo.svg\" alt=\"Bayfront Media\" width=\"250\" /\u003e\n\n- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github\u0026amp;utm_medium=direct)\n- [Bayfront Media GitHub](https://github.com/bayfrontmedia)\n\n## Requirements\n\n* PHP `^8.0` (Tested up to `8.4`)\n\n## Installation\n\n```\ncomposer require bayfrontmedia/php-time-helpers\n```\n\n## Usage\n\n- [getReadTime](#getreadtime)\n- [getDateTime](#getdatetime)\n- [isLeapYear](#isleapyear)\n- [humanArray](#humanarray)\n- [human](#human)\n- [toIso8601](#toiso8601)\n- [toTimezone](#totimezone)\n- [isTimezone](#istimezone)\n- [isFormat](#isformat)\n- [inPast](#inpast)\n- [inFuture](#infuture)\n- [isBefore](#isbefore)\n- [isAfter](#isafter)\n- [stopwatch](#stopwatch)\n\n\u003chr /\u003e\n\n### getReadTime\n\n**Description:**\n\nGet estimated minutes necessary to read content, based on reading a given amount of words per minute (WPM).\n\n**Parameters:**\n\n- `$content` (string)\n- `$wpm = 180` (int)\n\n**Returns:**\n\n- (int)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\n$content = 'This is a string of content.';\n\necho Time::getReadTime($content);\n\n```\n\n\u003chr /\u003e\n\n### getDateTime\n\n**Description:**\n\nReturns datetime of a given timestamp, or current time (default).\n\n**Parameters:**\n\n- `$timestamp = NULL` (int|null)\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\necho Time::getDateTime();\n\n```\n\n\u003chr /\u003e\n\n### isLeapYear\n\n**Description:**\n\nChecks if a given year is a leap year, using current year by default.\n\n**Parameters:**\n\n- `$year = NULL` (int|null): Four digit year, PHP `date('Y')` format\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\nif (Time::isLeapYear()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### humanArray\n\n**Description:**\n\nReturns human time as an array.\n\n**NOTE:** Due to discrepancies between the length of certain months and years (ie: leap year), elapsed time calculations for these units of time are approximate (30 days per month, 365 days per year).\n\n**Parameters:**\n\n- `$time_start` (int): Timestamp of starting time\n- `$time_end` (int): Timestamp of ending time\n- `$limit = 'year'` (string): Limit of time duration to calculate\n- `$language = NULL` (array|null): Custom language to return\n\nValid `$limit` values are:\n\n- `year`\n- `month`\n- `week`\n- `day`\n- `hour`\n- `minute`\n- `second`\n\nPassing a `$language` array allows you to translate the words returned by this method. The array keys must match those of the default array, which is:\n\n```\n$language = [\n    'year' =\u003e 'year',\n    'years' =\u003e 'years',\n    'month' =\u003e 'month',\n    'months' =\u003e 'months',\n    'week' =\u003e 'week',\n    'weeks' =\u003e 'weeks',\n    'day' =\u003e 'day',\n    'days' =\u003e 'days',\n    'hour' =\u003e 'hour',\n    'hours' =\u003e 'hours',\n    'minute' =\u003e 'minute',\n    'minutes' =\u003e 'minutes',\n    'second' =\u003e 'second',\n    'seconds' =\u003e 'seconds',\n    'past' =\u003e 'ago',\n    'present' =\u003e 'just now',\n    'future' =\u003e 'to go'\n];\n```\n\n**Returns:**\n\n- (array)\n\n#### Example:\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\n$start = time();\n$end = time() + 51001;\n\nprint_r(Time::humanArray($start, $end, 'minute'));\n```\n\n\u003chr /\u003e\n\n### human\n\n**Description:**\n\nReturns human time as a string.\n\nFor more information, see [humanArray](#humanarray).\n\n**Parameters:**\n\n- `$time_start` (int): Timestamp of starting time\n- `$time_end` (int): Timestamp of ending time\n- `$limit = 'year'` (string): Limit of time duration to calculate\n- `$language = NULL` (array| null): Custom language to return\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\n$start = time();\n$end = time() + 51001;\n\necho Time::human($start, $end);\n```\n\n\u003chr /\u003e\n\n\n### toIso8601\n\n**Description:**\n\nConvert UTC datetime to ISO-8601 format.\n\n**Parameters:**\n\n- `$datetime` (int|string): Any valid date/time formatted string or timestamp\n\n**Returns:**\n\n- (string)\n\n\u003chr /\u003e\n\n### toTimezone\n\n**Description:**\n\nConvert UTC datetime to format using timezone.\n\nSee: [https://www.php.net/manual/en/timezones.php](https://www.php.net/manual/en/timezones.php)\n\n**Parameters:**\n\n- `$datetime` (int|string): Any valid date/time formatted string or timestamp\n- `$timezone` (string): Any valid timezone identifier\n- `$format = 'U'` (string): Any valid date/time format\n\n**Returns:**\n\n- (string)\n\n\u003chr /\u003e\n\n### isTimezone\n\n**Description:**\n\nChecks if string is a valid timezone identifier.\n\nSee: [https://www.php.net/manual/en/timezones.php](https://www.php.net/manual/en/timezones.php)\n\n**Parameters:**\n\n- `$timezone` (string)\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\nif (Time::isTimezone('America/New_York')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isFormat\n\n**Description:**\n\nChecks if value is a given dateTime format.\n\nSee: [https://www.php.net/manual/en/function.date.php](https://www.php.net/manual/en/function.date.php)\n\n**Parameters:**\n\n- `$date` (string)\n- `$format` (string): Any valid date/time format\n- `$strict = 'true'` (bool)\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\n$date = '2020-07-18';\n\nif (Time::isFormat($date, 'Y-m-d')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### inPast\n\n**Description:**\n\nChecks if date/time is in the past.\n\nSee: [https://www.php.net/manual/en/datetime.formats.php](https://www.php.net/manual/en/datetime.formats.php)\n\n**Parameters:**\n\n- `$date` (string): Any valid date/time format\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\nif (Time::inPast('last Tuesday')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### inFuture\n\n**Description:**\n\nChecks if date/time is in the future.\n\nSee: [https://www.php.net/manual/en/datetime.formats.php](https://www.php.net/manual/en/datetime.formats.php)\n\n**Parameters:**\n\n- `$date` (string): Any valid date/time format\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\nif (Time::inFuture('2050-12-31')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isBefore\n\n**Description:**\n\nChecks if date/time is before a given date/time.\n\nSee: [https://www.php.net/manual/en/datetime.formats.php](https://www.php.net/manual/en/datetime.formats.php)\n\n**Parameters:**\n\n- `$date` (string): Any valid date/time format\n- `$before` (string): Any valid date/time format\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\nif (Time::isBefore('today', '2050-12-31')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isAfter\n\n**Description:**\n\nChecks if date/time is after a given date/time.\n\nSee: [https://www.php.net/manual/en/datetime.formats.php](https://www.php.net/manual/en/datetime.formats.php)\n\n**Parameters:**\n\n- `$date` (string): Any valid date/time format\n- `$after` (string): Any valid date/time format\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\nif (Time::isAfter('today', '2050-12-31')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### stopwatch\n\n**Description:**\n\nReturn the amount of time (in seconds) the callback took to execute.\n\n**Parameters:**\n\n- `$callable` (callback)\n- `$times = 1` (int): Number of times to iterate the callback\n- `$decimals = 5` (int): Number of decimal places to round to\n\n**Returns:**\n\n- (float)\n\n**Example:**\n\n```\nuse Bayfront\\TimeHelpers\\Time;\n\n$elapsed = Time::stopwatch(function() {\n\n    sleep(2);\n\n}, 2);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayfrontmedia%2Fphp-time-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbayfrontmedia%2Fphp-time-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayfrontmedia%2Fphp-time-helpers/lists"}