fix(#124): improve timezone support
Some checks failed
tests / ci (push) Has been cancelled

This commit is contained in:
Benjamin Nussbaum 2025-12-02 16:44:41 +01:00
parent 0322ec899e
commit b10bbca774
9 changed files with 168 additions and 12 deletions

View file

@ -121,6 +121,10 @@ class GenerateDefaultImagesCommand extends Command
$browserStage = new BrowserStage($browsershotInstance);
$browserStage->html($html);
// Set timezone from app config (no user context in this command)
$browserStage->timezone(config('app.timezone'));
$browserStage
->width($deviceModel->width)
->height($deviceModel->height);

View file

@ -12,6 +12,7 @@ use App\Liquid\Filters\StringMarkup;
use App\Liquid\Filters\Uniqueness;
use App\Liquid\Tags\TemplateTag;
use App\Services\PluginImportService;
use Carbon\Carbon;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -454,6 +455,12 @@ class Plugin extends Model
$renderedContent = '';
if ($this->markup_language === 'liquid') {
// Get timezone from user or fall back to app timezone
$timezone = $this->user->timezone ?? config('app.timezone');
// Calculate UTC offset in seconds
$utcOffset = (string) Carbon::now($timezone)->getOffset();
// Build render context
$context = [
'size' => $size,
@ -465,10 +472,10 @@ class Plugin extends Model
'timestamp_utc' => now()->utc()->timestamp,
],
'user' => [
'utc_offset' => '0',
'utc_offset' => $utcOffset,
'name' => $this->user->name ?? 'Unknown User',
'locale' => 'en',
'time_zone_iana' => config('app.timezone'),
'time_zone_iana' => $timezone,
],
'plugin_settings' => [
'instance_name' => $this->name,

View file

@ -27,6 +27,7 @@ class User extends Authenticatable // implements MustVerifyEmail
'assign_new_devices',
'assign_new_device_id',
'oidc_sub',
'timezone',
];
/**

View file

@ -25,7 +25,7 @@ class ImageGenerationService
{
public static function generateImage(string $markup, $deviceId): string
{
$device = Device::with(['deviceModel', 'palette', 'deviceModel.palette'])->find($deviceId);
$device = Device::with(['deviceModel', 'palette', 'deviceModel.palette', 'user'])->find($deviceId);
$uuid = Uuid::uuid4()->toString();
try {
@ -44,6 +44,10 @@ class ImageGenerationService
$browserStage = new BrowserStage($browsershotInstance);
$browserStage->html($markup);
// Set timezone from user or fall back to app timezone
$timezone = $device->user->timezone ?? config('app.timezone');
$browserStage->timezone($timezone);
if (config('app.puppeteer_window_size_strategy') === 'v2') {
$browserStage
->width($imageSettings['width'])
@ -352,7 +356,7 @@ class ImageGenerationService
try {
// Load device with relationships
$device->load(['palette', 'deviceModel.palette']);
$device->load(['palette', 'deviceModel.palette', 'user']);
// Get image generation settings from DeviceModel if available, otherwise use device settings
$imageSettings = self::getImageSettings($device);
@ -372,6 +376,10 @@ class ImageGenerationService
$browserStage = new BrowserStage($browsershotInstance);
$browserStage->html($html);
// Set timezone from user or fall back to app timezone
$timezone = $device->user->timezone ?? config('app.timezone');
$browserStage->timezone($timezone);
if (config('app.puppeteer_window_size_strategy') === 'v2') {
$browserStage
->width($imageSettings['width'])