create-prisma-php-app 1.28.5 → 1.28.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -180,16 +180,32 @@ final class Validator
180
180
  // Date Validation
181
181
 
182
182
  /**
183
- * Validate a date in a given format.
183
+ * Validate and format a date in a given format.
184
184
  *
185
- * @param mixed $value The value to validate.
186
- * @param string $format The date format.
187
- * @return string|null The valid date string or null if invalid.
185
+ * This function attempts to parse the input value as a date according to the specified format.
186
+ * If the value is valid, it returns the formatted date string. Otherwise, it returns null.
187
+ *
188
+ * @param mixed $value The value to validate. It can be a string or a DateTime object.
189
+ * @param string $format The expected date format (default is 'Y-m-d').
190
+ * @return string|null The formatted date string if valid, or null if invalid.
188
191
  */
189
192
  public static function date($value, string $format = 'Y-m-d'): ?string
190
193
  {
191
- $date = DateTime::createFromFormat($format, $value);
192
- return $date && $date->format($format) === $value ? $value : null;
194
+ try {
195
+ if ($value instanceof DateTime) {
196
+ $date = $value;
197
+ } else {
198
+ $date = DateTime::createFromFormat($format, (string)$value);
199
+ }
200
+
201
+ if ($date && $date->format($format) === (string)$value) {
202
+ return $date->format($format);
203
+ }
204
+ } catch (Exception) {
205
+ return null;
206
+ }
207
+
208
+ return null;
193
209
  }
194
210
 
195
211
  /**
@@ -203,7 +219,7 @@ final class Validator
203
219
  * @param string $format The format to use for the output date-time string. Default is 'Y-m-d H:i:s.u'.
204
220
  * @return string|null The formatted date-time string, or null if the value could not be parsed.
205
221
  */
206
- public static function dateTime($value, string $format = 'Y-m-d H:i:s.u'): ?string
222
+ public static function dateTime($value, string $format = 'Y-m-d H:i:s'): ?string
207
223
  {
208
224
  try {
209
225
  if ($value instanceof DateTime) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.28.5",
3
+ "version": "1.28.7",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",