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

When switching timezones convert in form when editing times

Klaus Zanders40ef4cf0ecdc
diff --git a/modules/costs/app/components/time_entries/days_and_hours_form.rb b/modules/costs/app/components/time_entries/days_and_hours_form.rb
index 0e25d1fe2b0..57a643f304c 100644
--- a/modules/costs/app/components/time_entries/days_and_hours_form.rb
+++ b/modules/costs/app/components/time_entries/days_and_hours_form.rb
@@ -49,7 +49,7 @@ module TimeEntries
type: "time",
required: start_and_end_time_required?,
label: TimeEntry.human_attribute_name(:start_time),
- value: model.start_timestamp&.strftime("%H:%M"),
+ value: start_time_in_local_time,
show_clear_button: true,
data: {
"time-entry-target" => "startTimeInput",
@@ -60,7 +60,7 @@ module TimeEntries
type: "time",
required: start_and_end_time_required?,
label: TimeEntry.human_attribute_name(:end_time),
- value: model.end_timestamp&.strftime("%H:%M"),
+ value: end_time_in_local_time,
show_clear_button: true,
caption: end_time_caption,
data: {
@@ -80,6 +80,26 @@ module TimeEntries
private
+ def start_time_in_local_time
+ return if model.start_timestamp.blank?
+
+ if model.user == User.current
+ model.start_timestamp.in_time_zone(User.current.time_zone)
+ else
+ model.start_timestamp
+ end.strftime("%H:%M")
+ end
+
+ def end_time_in_local_time
+ return if model.end_timestamp.blank?
+
+ if model.user == User.current
+ model.end_timestamp.in_time_zone(User.current.time_zone)
+ else
+ model.end_timestamp
+ end.strftime("%H:%M")
+ end
+
def show_start_and_end_time_fields?
TimeEntry.can_track_start_and_end_time?
end