Uniformize localized date
This commit is contained in:
parent
de9ba250e5
commit
87a2c7ed20
7 changed files with 6 additions and 75 deletions
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
//phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed
|
||||
//phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
|
||||
class NiceDate implements CastsAttributes
|
||||
{
|
||||
/**
|
||||
* Return a nice human readable carbon date.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
*/
|
||||
public function get($model, $key, $value, $attributes)
|
||||
{
|
||||
$value = Carbon::parse($value);
|
||||
return $value->isToday() ?
|
||||
trans('Aujourd\'hui à :time', [
|
||||
'time' => $value->isoFormat('HH:mm')
|
||||
]) : $value->isoFormat('YYYY/MM/DD HH:mm');
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a date string to a date time date.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
*/
|
||||
public function set($model, $key, $value, $attributes)
|
||||
{
|
||||
return Carbon::parse($value)->isoFormat('YYYY/MM/DD HH:mm');
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\NiceDate;
|
||||
use App\Enums\PublishedStatus;
|
||||
use App\Lib\ToolboxHelper;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
|
@ -148,14 +147,4 @@ class News extends Model
|
|||
ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id);
|
||||
ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* updated_at_date getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdatedAtDateAttribute(): string
|
||||
{
|
||||
return (new NiceDate())->get($this, 'published_at', $this->published_at, []);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Casts\HtmlColor;
|
||||
use App\Casts\NiceDate;
|
||||
use App\Enums\Sliders\SliderPosition;
|
||||
use App\Enums\Sliders\SliderType;
|
||||
use App\Lib\ToolboxHelper;
|
||||
|
|
@ -115,14 +114,4 @@ class Slider extends Model
|
|||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* updated_at_date getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdatedAtDateAttribute(): string
|
||||
{
|
||||
return (new NiceDate())->get($this, 'updated_at', $this->updated_at, []);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<div class="col-12 col-md-6 form-group">
|
||||
<label for="newsModelPublished" class="col-form-label"><b>{{ __('Publication') }}</b></label>
|
||||
@if(isset($newsModel) and $newsModel->published->equals(App\Enums\PublishedStatus::published()))
|
||||
<span class="col-form-label ms-3 fst-italic">{{ __('Publié le :date', ['date' => $newsModel->published_at->isoFormat('DD/MM/YYYY à HH:mm')]) }}</span>
|
||||
<span class="col-form-label ms-3 fst-italic">{{ __('Publié le :date', ['date' => $newsModel->published_at->formatLocalized('%d/%m/%Y à %I:%M')]) }}</span>
|
||||
@endif
|
||||
<select id="newsModelPublished" class="form-select" name="published" aria-describedby="newsModelPublishedHelp" required>
|
||||
<option value="" @if(is_null(old('published', $newsModel->published ?? null))) selected @endif disabled>{{ __('Séléctionnez un statut de publication') }}</option>
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
@case(App\Enums\PublishedStatus::published())
|
||||
<span class="badge bg-success text-wrap">{{ $newsModel->published_at ? __(':status le :date', [
|
||||
'status' => $newsModel->published->label,
|
||||
'date' => $newsModel->published_at->isoFormat('DD/MM/YYYY à HH:mm')
|
||||
'date' => $newsModel->published_at->formatLocalized('%d/%m/%Y à %I:%M')
|
||||
]) : '' }}</span>
|
||||
@break
|
||||
@case(App\Enums\PublishedStatus::archived())
|
||||
|
|
@ -71,7 +71,7 @@
|
|||
@endswitch
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge text-dark text-wrap">{{ $newsModel->updated_at_date }}</span>
|
||||
<span class="badge text-dark text-wrap">{{ $newsModel->updated_at->formatLocalized('%d/%m/%Y à %I:%M') }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@
|
|||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="sliderPublishedAt"><b>{{ __('Date de publication (Europe/Paris)') }}</b></label>
|
||||
<input id="sliderPublishedAt" name="publish_at" class="form-control publishTime" type="datetime-local" data-form-type="date" aria-describedby="sliderPublishAtHelp" value="{{ old('publish_at', ((isset($slider) and $slider->publish_at) ? $slider->publish_at->format('Y-m-d\TH:i') : '')) }}">
|
||||
<input id="sliderPublishedAt" name="publish_at" class="form-control publishTime" type="datetime-local" data-form-type="date" aria-describedby="sliderPublishAtHelp" value="{{ old('publish_at', ((isset($slider) and $slider->publish_at) ? $slider->publish_at->formatLocalized('%d/%m/%Y à %I:%M') : '')) }}">
|
||||
@include('back.modules.input-error', [
|
||||
'inputName' => 'publish_at', 'helperId' => 'sliderPublishAtHelp' , 'helper' => __('Uniquement pour planifier la publication, le slider deviendra visible.')
|
||||
])
|
||||
|
|
@ -90,7 +90,7 @@
|
|||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="sliderUnPublishedAt"><b>{{ __('Date de fin de publication (Europe/Paris)') }}</b></label>
|
||||
<input id="sliderUnPublishedAt" name="unpublish_at" class="form-control publishTime" type="datetime-local" data-form-type="date" aria-describedby="sliderUnPublishAtHelp" value="{{ old('unpublish_at', ((isset($slider) and $slider->unpublish_at) ? $slider->unpublish_at->format('Y-m-d\TH:i') : '')) }}">
|
||||
<input id="sliderUnPublishedAt" name="unpublish_at" class="form-control publishTime" type="datetime-local" data-form-type="date" aria-describedby="sliderUnPublishAtHelp" value="{{ old('unpublish_at', ((isset($slider) and $slider->unpublish_at) ? $slider->unpublish_at->formatLocalized('%d/%m/%Y à %I:%M') : '')) }}">
|
||||
@include('back.modules.input-error', [
|
||||
'inputName' => 'unpublish_at', 'helperId' => 'sliderUnPublishAtHelp' , 'helper' => __('Uniquement pour planifier la fin de la publication, le slider deviendra invisible.')
|
||||
])
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@
|
|||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge text-dark text-wrap">{{ $slider->updated_at_date }}</span>
|
||||
<span class="badge text-dark text-wrap">{{ $slider->updated_at->formatLocalized('%d/%m/%Y à %I:%M') }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue