diff --git a/README.md b/README.md
index 848fa2b..793a62b 100644
--- a/README.md
+++ b/README.md
@@ -8,10 +8,13 @@
The Verta is package for change solar calendar and gregorian together and provide helper function to use date and time.
Verta extend class PHP Datetime and Jalali, compatible with Carbon Package.
+This package has been created by Nasser Hekmati under the license of MIT.
## Quick view diff --git a/composer.json b/composer.json index 18d1e74..983cf7d 100755 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "hekmatinasser/verta", "description": "This Package helps developers to work with Jalali Datetime class for Laravel Framework PHP", "license": "MIT", + "type": "library", "authors": [ { "name": "Nasser Hekmati", @@ -20,7 +21,7 @@ "php": "^8.0", "illuminate/support": "^8.0|^9.0", "illuminate/validation": "^8.0|^9.0", - "hekmatinasser/jalali": "^8.0" + "hekmatinasser/jalali": "^8.1" }, "require-dev": { "orchestra/testbench": "^4.18|^5.20|^6.24|^7.0" diff --git a/src/Laravel/JalaliValidator.php b/src/Laravel/JalaliValidator.php index 4a8383a..47f72b9 100644 --- a/src/Laravel/JalaliValidator.php +++ b/src/Laravel/JalaliValidator.php @@ -2,6 +2,7 @@ namespace Hekmatinasser\Verta\Laravel; +use Exception; use Hekmatinasser\Verta\Verta; class JalaliValidator @@ -22,7 +23,7 @@ class JalaliValidator try { Verta::parseFormat($format, $value); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } @@ -48,7 +49,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->eq($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -72,7 +73,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->ne($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -94,7 +95,7 @@ class JalaliValidator try { Verta::parseFormat($format, $value); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } @@ -120,7 +121,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->eq($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -144,7 +145,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->ne($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -168,7 +169,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->gt($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -192,7 +193,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->gte($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -216,7 +217,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->gt($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -240,7 +241,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->gte($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -264,7 +265,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->lt($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -288,7 +289,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->lte($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -312,7 +313,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->lt($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } @@ -336,7 +337,7 @@ class JalaliValidator $base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null; return Verta::parseFormat($format, $value)->lte($base); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } diff --git a/src/Laravel/VertaServiceProvider.php b/src/Laravel/VertaServiceProvider.php index 21665a0..183d470 100644 --- a/src/Laravel/VertaServiceProvider.php +++ b/src/Laravel/VertaServiceProvider.php @@ -76,6 +76,10 @@ class VertaServiceProvider extends ServiceProvider public function boot() { $this->loadValidators(); + + Carbon::macro('toJalali', function ($timezone = null) { + return new Verta($this, $timezone); + }); } /** @@ -88,10 +92,6 @@ class VertaServiceProvider extends ServiceProvider $this->app->bind('verta', function ($app) { return new Verta(); }); - - Carbon::macro('toJalali', function ($timezone = null) { - return new Verta($this, $timezone); - }); } /** diff --git a/src/Verta.php b/src/Verta.php index 3544a99..278c7bf 100755 --- a/src/Verta.php +++ b/src/Verta.php @@ -2,8 +2,20 @@ namespace Hekmatinasser\Verta; +use Exception; use Hekmatinasser\Jalali\Jalali; +use Illuminate\Support\Carbon; class Verta extends Jalali { + /** + * Create a Carbon instance from Verta + * + * @return Carbon + * @throws Exception + */ + public function toCarbon(): Carbon + { + return new Carbon($this->datetime(), $this->timezone); + } }