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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
use UTC time zone as user pref if non is explicitly configured
ulferts6298b8762de4
diff --git a/app/components/settings/time_zone_setting_component.rb b/app/components/settings/time_zone_setting_component.rbindex 674ad6a53ce..772c8e35b01 100644--- a/app/components/settings/time_zone_setting_component.rb+++ b/app/components/settings/time_zone_setting_component.rb@@ -30,7 +30,7 @@module Settings##- # A text field to enter numeric values.+ # A select field to select a time zone from.class TimeZoneSettingComponent < ::ApplicationComponentoptions :form, :titleoptions container_class: "-wide"diff --git a/app/models/anonymous_user.rb b/app/models/anonymous_user.rbindex 27e4514d656..e73178ebddf 100644--- a/app/models/anonymous_user.rb+++ b/app/models/anonymous_user.rb@@ -49,7 +49,7 @@ class AnonymousUser < Userdef mail; nil end- def time_zone; nil end+ def time_zone; ActiveSupport::TimeZone["Etc/UTC"] enddef rss_key; nil enddiff --git a/app/models/user.rb b/app/models/user.rbindex 23e85c02b3b..7d6bc21a5f7 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -398,7 +398,7 @@ class User < Principalenddef log_successful_login- update_attribute(:last_login_on, Time.now)+ update_attribute(:last_login_on, Time.current)enddef prefdiff --git a/app/models/user_preference.rb b/app/models/user_preference.rbindex a2f49ede552..769ff84773f 100644--- a/app/models/user_preference.rb+++ b/app/models/user_preference.rb@@ -132,7 +132,7 @@ class UserPreference < ApplicationRecordenddef time_zone- super.presence || Setting.user_default_timezone.presence+ super.presence || Setting.user_default_timezone.presence || "Etc/UTC"enddef daily_remindersdiff --git a/app/views/users/_preferences.html.erb b/app/views/users/_preferences.html.erbindex 44a513b0527..45399a77431 100644--- a/app/views/users/_preferences.html.erb+++ b/app/views/users/_preferences.html.erb@@ -30,8 +30,10 @@ See COPYRIGHT and LICENSE files for more details.<%= render Settings::TimeZoneSettingComponent.new("time_zone",form: pref_fields,+ include_blank: false,container_class: (defined? input_size) ? "-#{input_size}" : "-wide")+%><div class="form--field"><%= pref_fields.select :theme, theme_options_for_select, container_class: '-middle' %>diff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rbindex 6604ba31fc6..5c107025668 100644--- a/lib_static/redmine/i18n.rb+++ b/lib_static/redmine/i18n.rb@@ -138,17 +138,14 @@ module Redminetime = time.to_time if time.is_a?(String)zone = User.current.time_zone- local = if zone- time.in_time_zone(zone)- else- (time.utc? ? time.to_time.localtime : time)- end+ 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))enddef format_time_zone- (User.current.time_zone || Time.zone).to_s[/\((.*?)\)/m, 1]+ User.current.time_zone.to_s[/\((.*?)\)/m, 1]enddef day_name(day)diff --git a/spec/lib/redmine/i18n_spec.rb b/spec/lib/redmine/i18n_spec.rbindex 384a08475f3..e2dabf1727b 100644--- a/spec/lib/redmine/i18n_spec.rb+++ b/spec/lib/redmine/i18n_spec.rb@@ -273,7 +273,10 @@ module OpenProjecttime_format: "%H %M",date_format: "%d %m %Y"} do- let!(:now) { Time.parse("2011-02-20 15:45:22") }+ let(:user_time_zone) { "" }+ let(:now) { Time.zone.parse("2011-02-20 15:45:22") }++ current_user { build_stubbed(:user, preferences: { time_zone: user_time_zone }) }it "with date and hours" doexpect(format_time(now))@@ -285,14 +288,19 @@ module OpenProject.to eql now.strftime("%H %M")end- it "with a utc to date and hours" do- expect(format_time(now.utc))- .to eql now.localtime.strftime("%d %m %Y %H %M")- end+ context "with another time zone configured for the user" do+ # Kathmandu has a +05:45 offset+ let(:user_time_zone) { "Kathmandu" }- it "with a utce to only hours" do- expect(format_time(now.utc, false))- .to eql now.localtime.strftime("%H %M")+ it "renders correctly for data and hours" do+ expect(format_time(now))+ .to eql "20 02 2011 21 30"+ end++ it "renders correctly for only hours" do+ expect(format_time(now, false))+ .to eql "21 30"+ endendcontext "with a different format defined", with_settings: {diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rbindex b0cd3fdff46..ee7c3286a1b 100644--- a/spec/models/user_preference_spec.rb+++ b/spec/models/user_preference_spec.rb@@ -222,4 +222,26 @@ RSpec.describe UserPreference doexpect(subject[:auto_hide_popups]).to eql(value_auto_hide_popups)endend++ describe "#time_zone" do+ context "with a time zone set and a default configured", with_settings: { user_default_timezone: "America/Los_Angeles" } do+ let(:settings) { { "time_zone" => "Africa/Algiers" } }++ it "returns the time zone set" do+ expect(preference.time_zone).to eql "Africa/Algiers"+ end+ end++ context "with no time zone configured but a default", with_settings: { user_default_timezone: "America/Los_Angeles" } do+ it "returns the default time zone" do+ expect(preference.time_zone).to eql "America/Los_Angeles"+ end+ end++ context "with neiter a time zone configured nor a default one", with_settings: { user_default_timezone: "" } do+ it "returns UTC" do+ expect(preference.time_zone).to eql "Etc/UTC"+ end+ end+ endend