Skip to Content

is_utc_timestamp()

Detect if a parameter is a UTC timestamp

PHP June 18, 2017

Usage

PHP
nebula()->is_utc_timestamp($timestamp)

Parameters

$timestamp
(Required) (Mixed) A string or integer to check if is UTC time
Default: None

Request or provide clarification »

Examples

PHP
$value = get_example_value_from_somewhere();
if ( is_utc_timestamp($value) ){
    //Do something if it is a timestamp
}

Additional Notes

Note: to avoid conflict with phone numbers, this function only supports UTC timestamps until May 18, 2033.

Source File

Located in /libs/Utilities/Utilities.php on line 836.

No Hooks

This function does not have any filters or actions available. Request one?
PHP
        public function is_utc_timestamp($timestamp){
            //If the timestamp contains any non-digit
            if ( preg_match('/\D/i', $timestamp) ){
                return false;
            }

            //If the timestamp is greater than May 18, 2033 (This function only supports up to this date to avoid conflicts with phone numbers. We'll have to figure out a new solution then.)
            if ( strlen($timestamp) === 10 && substr($timestamp, 0, 1) > 1 ){
                return false;
            }

            //If the timestamp has between 8 and 10 characters.
            if ( strlen($timestamp) >= 8 && strlen($timestamp) <= 10 ){
                $timestamp = intval($timestamp);
                if ( ctype_digit($timestamp) && strtotime(date('d-m-Y H:i:s', $timestamp)) === $timestamp ){
                    return true;
                }
            }

            return false;
        }

Override

This function can not be short-circuited with an override filter. Request one?