-
-
Save bmg1/7fd729f6d7c9b7cbdc3e2bee8a09d7c0 to your computer and use it in GitHub Desktop.
Validate if a Unix timestamp is valid.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Validate if a Unix timestamp is valid. | |
* | |
* @param $unixtimestamp | |
* @return bool | |
*/ | |
function datetime_IsUnixTimeStampValid($unixtimestamp) { | |
// | |
// | |
/////////////////////////////////////////////////////////////////////// | |
// Validate Date is between start and end of 32-bit Unix timestamps | |
// ref: https://stackoverflow.com/a/4684066/797620 | |
/////////////////////////////////////////////////////////////////////// | |
// | |
if ( !filter_var($unixtimestamp, FILTER_VALIDATE_INT, ['options' => ['min_range' => (int)0, 'max_range' => (int)2147483647]]) ) { | |
// | |
return false; | |
// | |
} | |
// | |
// | |
/////////////////////////////////////////////////////////////////////// | |
// Validate | |
// ref: https://stackoverflow.com/a/2524761/797620 | |
/////////////////////////////////////////////////////////////////////// | |
// | |
return ((string) (int) $unixtimestamp === $unixtimestamp) && ($unixtimestamp <= PHP_INT_MAX)&& ($unixtimestamp >= ~PHP_INT_MAX); | |
// | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test and check unix time stamp in php