-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
base: dev
Are you sure you want to change the base?
Changes from all commits
0495a96
b840990
8252131
6298b87
b27f164
1373a18
ebc6cdf
8b004a1
35ca717
48377fc
1d7fd3c
a5714f7
4c61ce1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' %> | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -116,15 +116,11 @@ def link_regex | |||||||||||||||||||||||||||
# Format the time to a date in the user time zone if one is set. | ||||||||||||||||||||||||||||
# If none is set and the time is in utc time zone (meaning it came from active record), format the date in the system timezone | ||||||||||||||||||||||||||||
# otherwise just use the date in the time zone attached to the time. | ||||||||||||||||||||||||||||
def format_time_as_date(time, format = nil) | ||||||||||||||||||||||||||||
def format_time_as_date(time, format: nil) | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation is not up-to-date anymore Here is a proposal: # Formats the given time as a date string according to the user's time zone and
# optional specified format.
#
# @param time [Time, String] The time to format. Can be a Time object or a String.
# @param format [String, nil] The strftime format to use for the date. If nil, the default
# date format from `Setting.date_format` is used.
# @return [String, nil] The formatted date string, or nil if the time is not provided.
def format_time_as_date(time, format: nil) |
||||||||||||||||||||||||||||
return nil unless time | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
zone = User.current.time_zone | ||||||||||||||||||||||||||||
local_date = (if zone | ||||||||||||||||||||||||||||
time.in_time_zone(zone) | ||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||
time.utc? ? time.localtime : time | ||||||||||||||||||||||||||||
end).to_date | ||||||||||||||||||||||||||||
local_date = time.in_time_zone(zone).to_date | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if format | ||||||||||||||||||||||||||||
local_date.strftime(format) | ||||||||||||||||||||||||||||
|
@@ -133,18 +129,25 @@ def format_time_as_date(time, format = nil) | |||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def format_time(time, include_date = true) | ||||||||||||||||||||||||||||
def format_time(time, include_date: true, format: Setting.time_format) | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's hard to know that this method uses user time zone without reading its code. We could rename it, but I propose adding some docs for it.
Suggested change
|
||||||||||||||||||||||||||||
return nil unless time | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||||||||||||||||||||||||||||
(format.blank? ? ::I18n.l(local, format: :time) : local.strftime(format)) | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Returns the offset to UTC (with utc prepended) currently active | ||||||||||||||||||||||||||||
# in the current users time zone. DST is factored in so the offset can | ||||||||||||||||||||||||||||
# shift over the course of the year | ||||||||||||||||||||||||||||
def formatted_time_zone_offset | ||||||||||||||||||||||||||||
# Doing User.current.time_zone and format that will not take heed of DST as it has no notion | ||||||||||||||||||||||||||||
# of a current time. | ||||||||||||||||||||||||||||
# https://github.com/rails/rails/issues/7297 | ||||||||||||||||||||||||||||
"UTC#{User.current.time_zone.now.formatted_offset}" | ||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def day_name(day) | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
|
@@ -97,8 +96,8 @@ def create # rubocop:disable Metrics/AbcSize | |
|
||
if call.success? | ||
text = I18n.t(:notice_successful_create) | ||
if User.current.time_zone.nil? | ||
link = I18n.t(:notice_timezone_missing, zone: Time.zone) | ||
unless User.current.pref.time_zone? | ||
link = I18n.t(:notice_timezone_missing, zone: formatted_time_zone_offset) | ||
text += " #{view_context.link_to(link, { controller: '/my', action: :settings, anchor: 'pref_time_zone' }, | ||
class: 'link_to_profile')}" | ||
Comment on lines
+99
to
102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried it. When there is no time zone set for the user, the message is displayed inviting the user to set a time zone, but the notification disappears after 5 seconds (or so). This is extremely short to read and take action. I suggest the success toast should not autoclose in this case. Probably worth a new bug work package for it. |
||
end | ||
|
@@ -289,17 +288,6 @@ def load_meetings(query) | |
.paginate(page: page_param, per_page: per_page_param) | ||
end | ||
|
||
def set_time_zone(&) | ||
zone = User.current.time_zone | ||
if zone.nil? | ||
localzone = Time.current.utc_offset | ||
localzone -= 3600 if Time.current.dst? | ||
zone = ::ActiveSupport::TimeZone[localzone] | ||
end | ||
|
||
Time.use_zone(zone, &) | ||
end | ||
Comment on lines
-292
to
-301
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Goodbye buggy code (a dst is not always 1h). |
||
|
||
def build_meeting | ||
@meeting = Meeting.new | ||
@meeting.project = @project | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not rely on the default implementation of
User#time_zone
? Implementation isAs a
pref
record does not exist forAnonymousUser
, it would be automatically built without touching the db and itstime_zone
will return the right value, so it should work as expected.Same applies for
DeletedUser
andSystemUser
.