feat: due resolution and cascade math
Also: StoresUtc trait normalizes datetime casts to UTC (controller ruling). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
23
core/app/Models/Concerns/StoresUtc.php
Normal file
23
core/app/Models/Concerns/StoresUtc.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use DateTimeInterface;
|
||||
|
||||
/**
|
||||
* Eloquent форматирует datetime без смещения, поэтому Carbon в чужом поясе
|
||||
* записался бы как «те же цифры в UTC». Приводим к UTC при присвоении.
|
||||
*/
|
||||
trait StoresUtc
|
||||
{
|
||||
public function setAttribute($key, $value)
|
||||
{
|
||||
if ($value instanceof DateTimeInterface
|
||||
&& in_array($this->getCasts()[$key] ?? null, ['datetime', 'immutable_datetime'], true)) {
|
||||
$value = CarbonImmutable::instance($value)->utc();
|
||||
}
|
||||
|
||||
return parent::setAttribute($key, $value);
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,14 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\DeliveryResult;
|
||||
use App\Models\Concerns\StoresUtc;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Delivery extends Model
|
||||
{
|
||||
use StoresUtc;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $attributes = ['meta' => '{}'];
|
||||
|
||||
@@ -5,12 +5,15 @@ namespace App\Models;
|
||||
use App\Enums\AfterDue;
|
||||
use App\Enums\DueMode;
|
||||
use App\Enums\EventState;
|
||||
use App\Models\Concerns\StoresUtc;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
use StoresUtc;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
|
||||
Reference in New Issue
Block a user