diff --git a/modules/costs/app/services/time_entries/set_attributes_service.rb b/modules/costs/app/services/time_entries/set_attributes_service.rb index 0a9f860ef1bd..08a513ba65e9 100644 --- a/modules/costs/app/services/time_entries/set_attributes_service.rb +++ b/modules/costs/app/services/time_entries/set_attributes_service.rb @@ -41,6 +41,11 @@ def set_attributes(_attributes) set_default_attributes(params) if model.new_record? + # move the timezone from the user + model.change_by_system do + model.time_zone = model.user.time_zone.name + end + # Always set the logging user as logged_by set_logged_by end diff --git a/modules/costs/spec/services/time_entries/set_attributes_service_spec.rb b/modules/costs/spec/services/time_entries/set_attributes_service_spec.rb index c80114b25eb1..dd7bf0b2f24a 100644 --- a/modules/costs/spec/services/time_entries/set_attributes_service_spec.rb +++ b/modules/costs/spec/services/time_entries/set_attributes_service_spec.rb @@ -148,6 +148,15 @@ end end + context "with a user with a defined timezone" do + it "extracts the current timezone from the user and stores it in the time entry" do + user.pref[:time_zone] = "America/Los_Angeles" + subject + + expect(time_entry_instance.time_zone).to eq "America/Los_Angeles" + end + end + context "with hours == 0" do let(:params) do {