Skip to content

Commit 8f5e323

Browse files
Copilotmaebeale
andcommitted
Use current_user.time_zone explicitly instead of Time.zone
Co-authored-by: maebeale <7607813+maebeale@users.noreply.github.com>
1 parent adadb8e commit 8f5e323

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

app/views/events/_form.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
type: "datetime-local",
5555
class:
5656
"w-full rounded border-gray-300 shadow-sm px-3 py-2 focus:ring-blue-500 focus:border-blue-500",
57-
value: @event.start_date&.in_time_zone(Time.zone)&.strftime("%Y-%m-%dT%H:%M"),
57+
value: @event.start_date&.in_time_zone(current_user&.time_zone || "UTC")&.strftime("%Y-%m-%dT%H:%M"),
5858
required: true %>
5959

6060
<% if f.object.errors[:start_date].any? %>
@@ -70,7 +70,7 @@
7070
type: "datetime-local",
7171
class:
7272
"w-full rounded border-gray-300 shadow-sm px-3 py-2 focus:ring-blue-500 focus:border-blue-500",
73-
value: @event.end_date&.in_time_zone(Time.zone)&.strftime("%Y-%m-%dT%H:%M"),
73+
value: @event.end_date&.in_time_zone(current_user&.time_zone || "UTC")&.strftime("%Y-%m-%dT%H:%M"),
7474
required: true %>
7575

7676
<% if f.object.errors[:end_date].any? %>
@@ -88,7 +88,7 @@
8888
type: "datetime-local",
8989
class:
9090
"w-full rounded border-gray-300 shadow-sm px-3 py-2 focus:ring-blue-500 focus:border-blue-500",
91-
value: @event.registration_close_date&.in_time_zone(Time.zone)&.strftime("%Y-%m-%dT%H:%M") %>
91+
value: @event.registration_close_date&.in_time_zone(current_user&.time_zone || "UTC")&.strftime("%Y-%m-%dT%H:%M") %>
9292

9393
<% if f.object.errors[:registration_close_date].any? %>
9494
<p class="text-red-500 text-sm mt-1">

spec/views/events/_form_timezone_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
it "converts times to user's timezone (Pacific)" do
2525
assign(:event, event.decorate)
2626

27-
# Mock Time.zone to return Pacific timezone (like ApplicationController does)
28-
allow(Time).to receive(:zone).and_return(ActiveSupport::TimeZone["Pacific Time (US & Canada)"])
29-
3027
render
3128

3229
# Pacific Time is UTC-8, so 8 PM UTC = 12 PM Pacific
@@ -56,8 +53,6 @@
5653
it "handles nil registration_close_date gracefully" do
5754
assign(:event, event.decorate)
5855

59-
allow(Time).to receive(:zone).and_return(ActiveSupport::TimeZone["Pacific Time (US & Canada)"])
60-
6156
render
6257

6358
# Should render all datetime input fields

0 commit comments

Comments
 (0)