From 8c1050f40aafa59e19982e9347b0520981715ef4 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 30 Jan 2024 01:21:51 +0100 Subject: [PATCH] Add wrapper around MD_STD::strtotime() that will throw an expected exception --- src/MD_STD.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/MD_STD.php b/src/MD_STD.php index 5aeb40f..67edd58 100644 --- a/src/MD_STD.php +++ b/src/MD_STD.php @@ -303,6 +303,27 @@ final class MD_STD { } + /** + * Wrapper around self::strtotime() that will return MDParseException (an expected + * exception) rather than MDInvalidInputDate (an unexpected exception). + * + * @param string $datetime String to convert. + * + * @return integer + */ + public static function strtotime_for_public_apis(string $datetime):int { + + try { + $output = self::strtotime($datetime); + } + catch (MDInvalidInputDate $e) { + throw new MDParseException($e->getMessage()); + } + + return $output; + + } + /** * Initializes a curl request with the given presets. *