I want to set the time zone of the app according to users timezone
in my app i want to set the time zone according to users login time
session(['userTimezone']) globally
session(['userTimezone']) globally
->timezone. Another way to think of this is that the data in the database should be normalized, not relative to any single user.->timezone[
"By Date" => [
"UTC" => "Tue, Jul 9, 2024 12:00 PM",
"Nashville" => "Tue, Jul 9, 2024 7:00 AM",
"Fiji" => "Wed, Jul 10, 2024 12:00 AM",
],
"Relative" => [
"UTC" => "1 day ago",
"Nashville" => "1 day ago",
"Fiji" => "1 day ago",
],
"Relative, 4 parts" => [
"UTC" => "1 day 9 hours 31 minutes 22 seconds ago",
"Nashville" => "1 day 9 hours 31 minutes 22 seconds ago",
"Fiji" => "1 day 9 hours 31 minutes 22 seconds ago",
],
]document.addEventListener("DOMContentLoaded", function () {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
Livewire.dispatch("updateUserTimezone", {timezone,});
});#[On('updateUserTimezone')]
public function updateUserTimezone($timezone)
{
session(['userTimezone' => $timezone]);
} TextColumn::make('created_at')
->timezone(session('userTimezone'))
->date(),use Illuminate\Support\Carbon;
$order = Carbon::createSafe(2024, 7, 9, 12, 0, 0, "UTC");
[
"By Date" => [
"UTC" => $order->timezone("UTC")->toDayDateTimeString(),
"Nashville" => $order->timezone("America/Chicago")->toDayDateTimeString(),
"Fiji" => $order->timezone("Pacific/Fiji")->toDayDateTimeString()
],
"Relative" => [
"UTC" => $order->timezone("UTC")->diffForHumans(),
"Nashville" => $order->timezone("America/Chicago")->diffForHumans(),
"Fiji" => $order->timezone("Pacific/Fiji")->diffForHumans()
],
"Relative, 4 parts" => [
"UTC" => $order->timezone("UTC")->diffForHumans(["parts" => 4]),
"Nashville" => $order
->timezone("America/Chicago")
->diffForHumans(["parts" => 4]),
"Fiji" => $order->timezone("Pacific/Fiji")->diffForHumans(["parts" => 4])
]
];