]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/DateTimeFormat.php
Remove unused dependency
[friendica.git] / src / Util / DateTimeFormat.php
index e29420e9ea41c272dcbbb63868bc0ffac6972b0a..dc6cbb044c450db50ccc7478625529c3284ee21e 100644 (file)
@@ -12,7 +12,7 @@ use DateTimeZone;
 use Exception;
 
 /**
- * @brief Temporal class
+ * Temporal class
  */
 class DateTimeFormat
 {
@@ -84,7 +84,7 @@ class DateTimeFormat
        }
 
        /**
-        * @brief General purpose date parse/convert/format function.
+        * General purpose date parse/convert/format function.
         *
         * @param string $s       Some parseable date/time string
         * @param string $tz_to   Destination timezone
@@ -181,4 +181,25 @@ class DateTimeFormat
 
                return true;
        }
+
+       /**
+        * Checks, if the given string is a date with the pattern YYYY-MM-DD
+        *
+        * @param string $dateString The given date
+        *
+        * @return boolean True, if the date is a valid pattern
+        */
+       public function isYearMonthDay(string $dateString)
+       {
+               $date = DateTime::createFromFormat('Y-m-d', $dateString);
+               if (!$date) {
+                       return false;
+               }
+
+               if (DateTime::getLastErrors()['error_count'] || DateTime::getLastErrors()['warning_count']) {
+                       return false;
+               }
+
+               return true;
+       }
 }