Skip to content

Commit

Permalink
localize timestamp in notification
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoraddatz committed Sep 17, 2024
1 parent 40997fb commit acbe7c6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Notifications/LoginCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ public function via(mixed $notifiable): array
return ['mail'];
}

/**
* This method is intended to implement your own logic to determine the user's timezone.
* Adjust this to avoid the user receiving wrong timestamps or adjust the texts to be less accurate.
*/
public static function getUserTimeZone(mixed $notifiable): string
{
return $notifiable->timezone ?? $notifiable->tz ?? config('app.timezone', 'UTC');
}

public function toMail(mixed $notifiable): MailMessage
{
$params = [
'app' => config('app.name'),
'name' => $notifiable->name,
'valid_until' => $notifiable->{config('totp-login.columns.code_valid_until')},
'code' => $this->code,
'ip' => $this->ip,
'valid_until' => $notifiable->{config('totp-login.columns.code_valid_until')}
?->tz(self::getUserTimeZone($notifiable)),
];

return (new MailMessage)
Expand Down

0 comments on commit acbe7c6

Please sign in to comment.