Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/56771 meeting timestamp in edit form not the same as in details #16567

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/settings/time_zone_setting_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

module Settings
##
# A text field to enter numeric values.
# A select field to select a time zone from.
class TimeZoneSettingComponent < ::ApplicationComponent
options :form, :title
options container_class: "-wide"
Expand Down
2 changes: 1 addition & 1 deletion app/models/anonymous_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def name(*_args); I18n.t(:label_user_anonymous) end

def mail; nil end

def time_zone; nil end
def time_zone; ActiveSupport::TimeZone["Etc/UTC"] end

def rss_key; nil end

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def log_failed_login
end

def log_successful_login
update_attribute(:last_login_on, Time.now)
update_attribute(:last_login_on, Time.current)
end

def pref
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_preference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def high_contrast_theme?
end

def time_zone
super.presence || Setting.user_default_timezone.presence
super.presence || Setting.user_default_timezone.presence || "Etc/UTC"
end

def daily_reminders
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/_preferences.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded new line

%>
<div class="form--field">
<%= pref_fields.select :theme, theme_options_for_select, container_class: '-middle' %>
Expand Down
9 changes: 3 additions & 6 deletions lib_static/redmine/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,14 @@ def format_time(time, include_date = true)

time = 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)
Comment on lines -141 to +137
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👏


(include_date ? "#{format_date(local)} " : "") +
(Setting.time_format.blank? ? ::I18n.l(local, format: :time) : local.strftime(Setting.time_format))
end

def format_time_zone
(User.current.time_zone || Time.zone).to_s[/\((.*?)\)/m, 1]
User.current.time_zone.to_s[/\((.*?)\)/m, 1]
end

def day_name(day)
Expand Down
24 changes: 16 additions & 8 deletions spec/lib/redmine/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ module OpenProject
time_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" do
expect(format_time(now))
Expand All @@ -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"
end
end

context "with a different format defined", with_settings: {
Expand Down
22 changes: 22 additions & 0 deletions spec/models/user_preference_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,26 @@
expect(subject[:auto_hide_popups]).to eql(value_auto_hide_popups)
end
end

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
end
end