Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

remove around_action altering the server`s time zone for this request

ulfertsebc6cdfd645c
diff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rb
index 481c9d13527..8dff1872b47 100644
--- a/lib_static/redmine/i18n.rb
+++ b/lib_static/redmine/i18n.rb
@@ -129,7 +129,7 @@ module Redmine
end
end
- def format_time(time, include_date = true)
+ def format_time(time, include_date = true, format: Setting.time_format)
return nil unless time
time = time.to_time if time.is_a?(String)
@@ -137,7 +137,7 @@ module Redmine
local = time.in_time_zone(zone)
(include_date ? "#{format_date(local)} " : "") +
- (Setting.time_format.blank? ? ::I18n.l(local, format: :time) : local.strftime(Setting.time_format))
+ (format.blank? ? ::I18n.l(local, format: :time) : local.strftime(format))
end
# Returns the offset to UTC (with utc prepended) currently active
diff --git a/modules/meeting/app/components/meetings/side_panel/details_form_component.rb b/modules/meeting/app/components/meetings/side_panel/details_form_component.rb
index e290cdbe3e7..bbd26b4c5cf 100644
--- a/modules/meeting/app/components/meetings/side_panel/details_form_component.rb
+++ b/modules/meeting/app/components/meetings/side_panel/details_form_component.rb
@@ -45,11 +45,11 @@ module Meetings
private
def start_date_initial_value
- @meeting.start_time&.strftime("%Y-%m-%d")
+ format_time_as_date(@meeting.start_time, "%Y-%m-%d")
end
def start_time_initial_value
- @meeting.start_time&.strftime("%H:%M")
+ format_time(@meeting.start_time, false, format: "%H:%M")
end
end
end
diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb
index 44fcb157e7e..762142ceeb9 100644
--- a/modules/meeting/app/controllers/meetings_controller.rb
+++ b/modules/meeting/app/controllers/meetings_controller.rb
@@ -27,7 +27,6 @@
#++
class MeetingsController < ApplicationController
- around_action :set_time_zone
before_action :load_and_authorize_in_optional_project, only: %i[index new show create history]
before_action :verify_activities_module_activated, only: %i[history]
before_action :determine_date_range, only: %i[history]
@@ -289,10 +288,6 @@ class MeetingsController < ApplicationController
.paginate(page: page_param, per_page: per_page_param)
end
- def set_time_zone(&)
- Time.use_zone(User.current.time_zone, &)
- end
-
def build_meeting
@meeting = Meeting.new
@meeting.project = @project
diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb
index 58b362589eb..47e0633c671 100644
--- a/modules/meeting/app/models/meeting.rb
+++ b/modules/meeting/app/models/meeting.rb
@@ -253,14 +253,15 @@ class Meeting < ApplicationRecord
def set_initial_values
# set defaults
- write_attribute(:start_time, Date.tomorrow + 10.hours) if start_time.nil?
+ # Start date is set to tomorrow at 10 AM (Current users local time)
+ write_attribute(:start_time, User.current.time_zone.now.at_midnight + 34.hours) if start_time.nil?
self.duration ||= 1
update_derived_fields
end
def update_derived_fields
- @start_date = start_time.to_date.iso8601
- @start_time_hour = start_time.strftime("%H:%M")
+ @start_date = format_time_as_date(start_time, "%Y-%m-%d")
+ @start_time_hour = format_time(start_time, false, format: "%H:%M")
end
private
diff --git a/modules/meeting/app/views/meetings/_form.html.erb b/modules/meeting/app/views/meetings/_form.html.erb
index af48e62e620..abf981a7d72 100644
--- a/modules/meeting/app/views/meetings/_form.html.erb
+++ b/modules/meeting/app/views/meetings/_form.html.erb
@@ -160,7 +160,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= Meeting.human_attribute_name(:start_time) %>
<label lang="en">
<%= t(:label_time_zone) %>
- <%= Time.zone.to_s %>
+ <%= formatted_time_zone_offset %>
</label>
</label>
<%= f.text_field :start_time_hour,
@@ -169,7 +169,7 @@ See COPYRIGHT and LICENSE files for more details.
type: 'time',
no_label: true,
step: 5.minutes,
- suffix: Time.zone.to_s,
+ suffix: formatted_time_zone_offset,
container_class: '-xslim' %>
</div>
</div>
diff --git a/modules/meeting/app/views/meetings/show.html.erb b/modules/meeting/app/views/meetings/show.html.erb
index 15b97a0bd21..2028a375d13 100644
--- a/modules/meeting/app/views/meetings/show.html.erb
+++ b/modules/meeting/app/views/meetings/show.html.erb
@@ -101,7 +101,7 @@ See COPYRIGHT and LICENSE files for more details.
<div class="grid-content small-6">
<p>
<strong><%= Meeting.human_attribute_name(:start_time) %></strong>: <%= format_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>
- - <%= format_time @meeting.end_time, false %> <%= Time.zone %></p>
+ - <%= format_time @meeting.end_time, false %> <%= formatted_time_zone_offset %></p>
</div>
<div class="grid-content small-6">
<p>
diff --git a/spec/lib/redmine/i18n_spec.rb b/spec/lib/redmine/i18n_spec.rb
index c122a363bf5..df49b76b19d 100644
--- a/spec/lib/redmine/i18n_spec.rb
+++ b/spec/lib/redmine/i18n_spec.rb
@@ -41,12 +41,12 @@ module OpenProject
describe "with user time zone" do
let(:user_time_zone) { "Europe/Athens" }
- it "returns a date in the user timezone for a utc timestamp" do
+ it "returns a date string in the user timezone for a utc timestamp" do
time = ActiveSupport::TimeZone["UTC"].local(2013, 6, 30, 23, 59)
expect(format_time_as_date(time, format)).to eq "01/07/2013"
end
- it "returns a date in the user timezone for a non-utc timestamp" do
+ it "returns a date string in the user timezone for a non-utc timestamp" do
time = ActiveSupport::TimeZone["Berlin"].local(2013, 6, 30, 23, 59)
expect(format_time_as_date(time, format)).to eq "01/07/2013"
end
@@ -55,12 +55,12 @@ module OpenProject
describe "without user time zone" do
let(:user_time_zone) { "" }
- it "returns a date in the utc timezone for a utc timestamp" do
+ it "returns a date string in the utc timezone for a utc timestamp" do
time = ActiveSupport::TimeZone["UTC"].local(2013, 6, 30, 23, 59)
expect(format_time_as_date(time, format)).to eq "30/06/2013"
end
- it "returns a date in the utc timezone for a non-utc timestamp" do
+ it "returns a date string in the utc timezone for a non-utc timestamp" do
time = ActiveSupport::TimeZone["Berlin"].local(2013, 6, 30, 23, 59)
expect(format_time_as_date(time, format)).to eq "30/06/2013"
end
@@ -278,6 +278,11 @@ module OpenProject
.to eql now.strftime("%H %M")
end
+ it "renders correctly for only hours and when providing a custom format" do
+ expect(format_time(now, false, format: "%H:%M"))
+ .to eql now.strftime("%H:%M")
+ end
+
context "with another time zone configured for the user" do
# Kathmandu has a +05:45 offset
let(:user_time_zone) { "Kathmandu" }
@@ -291,6 +296,11 @@ module OpenProject
expect(format_time(now, false))
.to eql "21 30"
end
+
+ it "renders correctly for only hours and when providing a custom format" do
+ expect(format_time(now, false, format: "%H:%M"))
+ .to eql "21:30"
+ end
end
context "with a different format defined", with_settings: {