add syntax sugar for Carbon conversions
This commit is contained in:
1 parent
3e1ef52534
commit
264b4488a6
5 files changed
+39
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace Hekmatinasser\Verta\Laravel;
|
||||
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
@@ -87,6 +88,10 @@ class VertaServiceProvider extends ServiceProvider
|
||||
$this->app->bind('verta', function ($app) {
|
||||
return new Verta();
|
||||
});
|
||||
|
||||
Carbon::macro('toJalali', function ($timezone = null) {
|
||||
return new Verta($this, $timezone);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Hekmatinasser\Verta\Traits;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Illuminate\Support\Carbon;
|
||||
use InvalidArgumentException;
|
||||
|
||||
trait Creator
|
||||
@@ -128,6 +129,16 @@ trait Creator
|
||||
return new DateTime(date('Y-m-d H:i:s', $this->getTimestamp()), $this->getTimezone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Carbon instance from Verta
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function toCarbon()
|
||||
{
|
||||
return Carbon::instance($this->datetime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Verta instance from a DateTime one
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user