Skip to content

Commit

Permalink
Initial Laravel 6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexej Krzewitzki committed Mar 25, 2022
1 parent 0eba5f5 commit b80f28e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ vendor/
composer.lock
coverage/
/nbproject/private/
/nbproject
/nbproject
.history
8 changes: 6 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## Version History

### v. 0.1
### v. 1.0.0

- Laravel 6 support
- Updated Date dependency

- initial release
### v. 0.1

- initial release
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"name": "flobbos/laravel-datable",
"description": "A tiny Laravel package for easily switching localized dates",
"keywords": ["laravel", "date", "carbon"],
"keywords": [
"laravel",
"date",
"carbon"
],
"license": "MIT",
"authors": [
{
Expand All @@ -11,17 +15,15 @@
}
],
"require": {
"php": ">=5.6.0",
"illuminate/support": ">=5.3.0",
"jenssegers/date": "^3.2"
"php": ">=7.2.0",
"illuminate/support": ">=6.0",
"jenssegers/date": "^3.5"
},
"autoload": {
"psr-4": {
"Flobbos\\Datable\\": "src/Datable/"
},
"classmap": [
]
"classmap": []
},

"minimum-stability": "dev"
}
}
19 changes: 10 additions & 9 deletions src/Datable/Datable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Jenssegers\Date\Date;

trait Datable {
protected function asDateTime($value){
trait Datable
{
protected function asDateTime($value)
{
Date::setLocale(app()->getLocale());
// If this value is already a Carbon instance, we shall just return it as is.
// This prevents us having to re-instantiate a Date instance when we know
Expand All @@ -16,12 +16,13 @@ protected function asDateTime($value){
return $value;
}

// If the value is already a DateTime instance, we will just skip the rest of
// these checks since they will be a waste of time, and hinder performance
// when checking the field. We will just return the DateTime right away.
// If the value is already a DateTime instance, we will just skip the rest of
// these checks since they will be a waste of time, and hinder performance
// when checking the field. We will just return the DateTime right away.
if ($value instanceof DateTimeInterface) {
return new Date(
$value->format('Y-m-d H:i:s.u'), $value->getTimezone()
$value->format('Y-m-d H:i:s.u'),
$value->getTimezone()
);
}

Expand All @@ -44,4 +45,4 @@ protected function asDateTime($value){
// that is returned back out to the developers after we convert it here.
return Date::createFromFormat($this->getDateFormat(), $value);
}
}
}

0 comments on commit b80f28e

Please sign in to comment.