Download the PHP package bayfrontmedia/php-time-helpers without Composer
On this page you can find all versions of the php package bayfrontmedia/php-time-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bayfrontmedia/php-time-helpers
More information about bayfrontmedia/php-time-helpers
Files in bayfrontmedia/php-time-helpers
Package php-time-helpers
Short Description Helper class to provide useful time related functions.
License MIT
Homepage https://github.com/bayfrontmedia/php-time-helpers
Informations about the package php-time-helpers
PHP time helpers
Helper class to provide useful time related functions.
- License
- Author
- Requirements
- Installation
- Usage
License
This project is open source and available under the MIT License.
Author
Requirements
- PHP
^8.0(Tested up to8.4)
Installation
Usage
- getReadTime
- getDateTime
- isLeapYear
- humanArray
- human
- toIso8601
- toTimezone
- isTimezone
- isFormat
- inPast
- inFuture
- isBefore
- isAfter
- stopwatch
- isWeekday
- isWeekend
- getRandomDate
- lastMonday
- lastTuesday
- lastWednesday
- lastThursday
- lastFriday
- lastSaturday
- lastSunday
- nextMonday
- nextTuesday
- nextWednesday
- nextThursday
- nextFriday
- nextSaturday
- nextSunday
getReadTime
Description:
Get estimated minutes necessary to read content, based on reading a given amount of words per minute (WPM).
Parameters:
$content(string)$wpm = 180(int)
Returns:
- (int)
Example:
getDateTime
Description:
Returns datetime of a given timestamp, or current time (default).
Parameters:
$timestamp = NULL(int|null)
Returns:
- (string)
Example:
isLeapYear
Description:
Checks if a given year is a leap year, using current year by default.
Parameters:
$year = NULL(int|null): Four digit year, PHPdate('Y')format
Returns:
- (bool)
Example:
humanArray
Description:
Returns human time as an array.
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).
Parameters:
$time_start(int): Timestamp of starting time$time_end(int): Timestamp of ending time$limit = 'year'(string): Limit of time duration to calculate$language = NULL(array|null): Custom language to return
Valid $limit values are:
yearmonthweekdayhourminutesecond
Passing 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:
Returns:
- (array)
Example:
human
Description:
Returns human time as a string.
For more information, see humanArray.
Parameters:
$time_start(int): Timestamp of starting time$time_end(int): Timestamp of ending time$limit = 'year'(string): Limit of time duration to calculate$language = NULL(array| null): Custom language to return
Returns:
- (string)
Example:
toIso8601
Description:
Convert UTC datetime to ISO-8601 format.
Parameters:
$datetime(int|string): Any valid date/time formatted string or timestamp
Returns:
- (string)
toTimezone
Description:
Convert UTC datetime to format using timezone.
See: https://www.php.net/manual/en/timezones.php
Parameters:
$datetime(int|string): Any valid date/time formatted string or timestamp$timezone(string): Any valid timezone identifier$format = 'U'(string): Any valid date/time format
Returns:
- (string)
isTimezone
Description:
Checks if string is a valid timezone identifier.
See: https://www.php.net/manual/en/timezones.php
Parameters:
$timezone(string)
Returns:
- (bool)
Example:
isFormat
Description:
Checks if value is a given dateTime format.
See: https://www.php.net/manual/en/function.date.php
Parameters:
$date(string)$format(string): Any valid date/time format$strict = 'true'(bool)
Returns:
- (bool)
Example:
inPast
Description:
Checks if date/time is in the past.
See: https://www.php.net/manual/en/datetime.formats.php
Parameters:
$date(string): Any valid date/time format
Returns:
- (bool)
Example:
inFuture
Description:
Checks if date/time is in the future.
See: https://www.php.net/manual/en/datetime.formats.php
Parameters:
$date(string): Any valid date/time format
Returns:
- (bool)
Example:
isBefore
Description:
Checks if date/time is before a given date/time.
See: https://www.php.net/manual/en/datetime.formats.php
Parameters:
$date(string): Any valid date/time format$before(string): Any valid date/time format
Returns:
- (bool)
Example:
isAfter
Description:
Checks if date/time is after a given date/time.
See: https://www.php.net/manual/en/datetime.formats.php
Parameters:
$date(string): Any valid date/time format$after(string): Any valid date/time format
Returns:
- (bool)
Example:
stopwatch
Description:
Return the amount of time (in seconds) the callback took to execute.
Parameters:
$callable(callback)$times = 1(int): Number of times to iterate the callback$decimals = 5(int): Number of decimal places to round to
Returns:
- (float)
Example:
isWeekday
Description:
Is date a weekday?
Parameters:
$date(string): Any valid date/time format
Returns:
- (bool)
isWeekend
Description:
Is date a weekend?
Parameters:
$date(string): Any valid date/time format
Returns:
- (bool)
getRandomDate
Description:
Get random date between two dates.
Parameters:
$start_date = '1900-01-01(string): Any valid date/time format$end_date = null(string|null): Any valid date/time format. Ifnull, the current date will be used$format = 'Y-m-d H:i:s'(string): Date format to be returned
Returns:
- (string)
lastMonday
Description:
Get date of the previous occurring Monday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Monday
Returns:
- (string)
lastTuesday
Description:
Get date of the previous occurring Tuesday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Tuesday
Returns:
- (string)
lastWednesday
Description:
Get date of the previous occurring Wednesday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Wednesday
Returns:
- (string)
lastThursday
Description:
Get date of the previous occurring Thursday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Thursday
Returns:
- (string)
lastFriday
Description:
Get date of the previous occurring Friday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Friday
Returns:
- (string)
lastSaturday
Description:
Get date of the previous occurring Saturday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Saturday
Returns:
- (string)
lastSunday
Description:
Get date of the previous occurring Sunday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Sunday
Returns:
- (string)
nextMonday
Description:
Get date of the next occurring Monday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Monday
Returns:
- (string)
nextTuesday
Description:
Get date of the next occurring Tuesday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Tuesday
Returns:
- (string)
nextWednesday
Description:
Get date of the next occurring Wednesday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Wednesday
Returns:
- (string)
nextThursday
Description:
Get date of the next occurring Thursday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Thursday
Returns:
- (string)
nextFriday
Description:
Get date of the next occurring Friday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Friday
Returns:
- (string)
nextSaturday
Description:
Get date of the next occurring Saturday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Saturday
Returns:
- (string)
nextSunday
Description:
Get date of the next occurring Sunday from a given date.
Parameters:
$date(string): Any valid date/time format$format = 'Y-m-d H:i:s'(string): Date format to be returned$include_self = true(bool): If true, the current date will be returned if it falls on a Sunday
Returns:
- (string)