PHP Classes

File: docs/dates.md

Recommend this page to a friend!
  Classes of Eric Sizemore   Utility   docs/dates.md   Download  
File: docs/dates.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Utility
Collection of various PHP utility functions
Author: By
Last change:
Date: 2 months ago
Size: 1,633 bytes
 

Contents

Class file image Download

Dates

Esi\Utility\Dates

timeDifference

Formats the difference between two timestamps to be human-readable.

use Esi\Utility\Dates;

$diff = Dates::timeDifference(time() - (604800 * 5));

echo $diff; // '1 month(s) old'

timezoneInfo

Retrieves information about a timezone.

use Esi\Utility\Dates;

$zoneInfo = Dates::timezoneInfo('America/New_York');
print_r($zoneInfo);

/*
Array
(
    [offset] => -5
    [country] => US
    [latitude] => 40.71416
    [longitude] => -74.00639
    [dst] => 
)
*/

validTimezone

Determines if a given timezone is valid, according to PHP's Timezone List

use Esi\Utility\Dates;

var_dump(Dates::validTimezone('InvalidTimezone')); // bool(false)
var_dump(Dates::validTimezone('America/New_York')); // bool(true)

validateTimestamp

Determines if a given timestamp matches the valid range that is typically found in a unix timestamp (at least in PHP). Typically, a timestamp for PHP can be valid if it is either 0 or between 8 and 11 digits in length.

use Esi\Utility\Dates;

var_dump(Dates::validateTimestamp(123456789012)); // bool(false)
var_dump(Dates::validateTimestamp(1234567)); // bool(false)
var_dump(Dates::validateTimestamp(123456789)); // bool(true)