From a8d7f18c9f47a9fd3879262dc18db9e50b67991d Mon Sep 17 00:00:00 2001 From: chenxi Date: Tue, 10 Nov 2026 17:17:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=B3=BB=E7=BB=9F=E5=8C=96=E5=BE=85?= =?UTF-8?q?=E5=8A=9E=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=E6=8C=89=E4=B8=8A?= =?UTF-8?q?=E6=B5=B7=E6=97=B6=E5=8C=BA=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Business/SystemizationTodo.php | 14 +++++++ .../pages/systemization-todos.blade.php | 2 +- .../Business/SystemizationTodosTest.php | 39 ++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/Models/Business/SystemizationTodo.php b/app/Models/Business/SystemizationTodo.php index c53a1ce8..92ef4109 100644 --- a/app/Models/Business/SystemizationTodo.php +++ b/app/Models/Business/SystemizationTodo.php @@ -93,6 +93,20 @@ class SystemizationTodo extends Model return $this->belongsTo(User::class, 'created_by')->withTrashed(); } + public function creationTimeLabel(): string + { + if ($this->created_at === null) { + return ''; + } + + $timezone = (string) config('app.platform_timezone', config('app.timezone', 'Asia/Shanghai')); + if ($timezone === '') { + $timezone = 'Asia/Shanghai'; + } + + return $this->created_at->copy()->setTimezone($timezone)->format('Y-m-d H:i'); + } + public function attachments(): HasMany { return $this->hasMany(SystemizationTodoAttachment::class, 'systemization_todo_id') diff --git a/resources/views/business/pages/systemization-todos.blade.php b/resources/views/business/pages/systemization-todos.blade.php index 9679939a..d4aa5a88 100644 --- a/resources/views/business/pages/systemization-todos.blade.php +++ b/resources/views/business/pages/systemization-todos.blade.php @@ -767,7 +767,7 @@ {{ $item->creator?->name ?: '—' }} - {{ $item->created_at?->format('Y-m-d H:i') ?: '—' }} + {{ $item->creationTimeLabel() ?: '—' }} @php($ownerNames = $personNames($item->owner_display ?? null)) created_by; $createdAt = $todo->created_at->format('Y-m-d H:i:s'); - $displayedCreatedAt = $todo->created_at->format('Y-m-d H:i'); + $displayedCreatedAt = $todo->creationTimeLabel(); $this->get(route('business.pages.show', [ 'section' => 'other', @@ -1402,6 +1402,43 @@ class SystemizationTodosTest extends FeatureTestCase } } + public function test_creation_time_is_displayed_in_the_platform_timezone(): void + { + $originalTimezone = config('app.timezone'); + $originalPlatformTimezone = config('app.platform_timezone'); + + try { + config([ + 'app.timezone' => 'Europe/London', + 'app.platform_timezone' => 'Asia/Shanghai', + ]); + date_default_timezone_set('Europe/London'); + Carbon::setTestNow('2026-11-10 08:21:30'); + + $this->loginAs(); + $todo = $this->createTodo('收入', '创建时间测试', '创建时间按上海展示', '2026-11-12', 1); + $todo->refresh(); + + $this->assertSame('2026-11-10 08:21', $todo->created_at->format('Y-m-d H:i')); + $this->assertSame('2026-11-10 16:21', $todo->creationTimeLabel()); + + $this->get(route('business.pages.show', [ + 'section' => 'other', + 'page' => 'systemization-todos', + ]))->assertOk()->assertSee( + 'data-sys-todo-immutable="created_at">2026-11-10 16:21', + false, + ); + } finally { + Carbon::setTestNow(); + config([ + 'app.timezone' => $originalTimezone, + 'app.platform_timezone' => $originalPlatformTimezone, + ]); + date_default_timezone_set((string) $originalTimezone); + } + } + public function test_edit_redirect_keeps_current_filters_and_highlight(): void { $this->loginAs(); -- 2.47.2