Created
May 5, 2020 17:00
-
-
Save banqhsia/52832b26ee47e937e1ef105c75d8376f to your computer and use it in GitHub Desktop.
Macros additional useful methods to PHP Carbon package.
This file contains hidden or 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
<?php | |
/** | |
* 給定時間日期是否合法 | |
* | |
* @param string|null $time | |
* @param \DateTimeZone|string|null $tz | |
* @return bool | |
*/ | |
Carbon::macro('recognized', function ($time = null, $tz = null) { | |
return (bool) @static::parse($time, $tz); | |
}); | |
/** | |
* 給定時間日期是否「不」合法 | |
* | |
* @param string|null $time | |
* @param \DateTimeZone|string|null $tz | |
* @return bool | |
*/ | |
Carbon::macro('unrecognized', function ($time = null, $tz = null) { | |
return ! static::recognized(...func_get_args()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment