This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <x-date-time-zone :date="$model->created_at" /> | |
| <x-date-time-zone :date="$model->created_at" format="d-m-Y H:i:s"/> | |
| <x-date-time-zone :date="$model->created_at" format="d/m/Y<\b\r>H:i"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\View\Components; | |
| use App\Helpers\Helpers; | |
| use Carbon\Carbon; | |
| use Illuminate\View\Component; | |
| class DateTimeZone extends Component | |
| { | |
| public Carbon $date; | |
| public mixed $format; | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function getCreatedAtAttribute($value): Carbon | |
| { | |
| return Carbon::parse($value)->timezone(Helpers::getUserTimeZone()); | |
| } | |
| public function getUpdatedAtAttribute($value): Carbon | |
| { | |
| return Carbon::parse($value)->timezone(Helpers::getUserTimeZone()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $request->merge([ | |
| 'created_at' => Carbon::parse($request->input('created_at'), Helpers::getUserTimeZone()) | |
| ->setTimeZone(config('app.timezone')) | |
| ->format('Y-m-d H:i:s'), | |
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.33/moment-timezone-with-data.min.js"></script> | |
| <script> | |
| $(document).ready(function() { | |
| console.log(moment.tz.guess()); | |
| }); | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="col-md-4"> | |
| <label class="required" for="timezone">{{ __('TimeZone') }}</label> | |
| <select class="form-control" name="timezone" id="timezone"> | |
| @foreach(Helpers::getTimeZoneList() as $timezone => $timezone_gmt_diff) | |
| <option value="{{ $timezone }}" {{ ( $timezone === old('timezone', $user->timezone)) ? 'selected' : '' }}> | |
| {{ $timezone_gmt_diff }} | |
| </option> | |
| @endforeach | |
| </select> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| static public function getUserTimeZone() { | |
| return optional(auth()->user())->timezone ?? config('app.timezone'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| static public function getTimeZoneList() | |
| { | |
| return \Cache::rememberForever('timezones_list_collection', function () { | |
| $timestamp = time(); | |
| foreach (timezone_identifiers_list(\DateTimeZone::ALL) as $key => $value) { | |
| date_default_timezone_set($value); | |
| $timezone[$value] = $value . ' (UTC ' . date('P', $timestamp) . ')'; | |
| } | |
| return collect($timezone)->sortKeys(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Helpers; | |
| use Illuminate\Support\Facades\App; | |
| class Helpers { | |
| //... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function setTimeZoneAttribute($value) { | |
| $this->attributes['timezone'] = $value == config('app.timezone') || is_null($value) ? null : $value; | |
| } |
NewerOlder