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
correctly handle timezone setting for start time
Klaus Zandersc91d7eb79b40
diff --git a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rbindex 8d80dfa5543..6e85f0a0eb7 100644--- a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb+++ b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb@@ -144,12 +144,19 @@ module APIif ts.nil?represented.start_timestamp = nil- elsif ts.to_date != represented.spent_on+ return+ end++ if represented.user.present?+ ts = ts.in_time_zone(represented.user.time_zone)+ end++ if ts.to_date == represented.spent_on+ represented.start_time = ts.strftime("%H:%M")+ elseraise API::Errors::Validation.new("start_time",I18n.t("api_v3.errors.validation.start_time_different_date",spent_on: represented.spent_on, start_time: ts.to_date))- else- represented.start_time = ts.strftime("%H:%M")endenddiff --git a/modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_parsing_spec.rb b/modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_parsing_spec.rbindex 884ac9a0531..72b5c0bc57b 100644--- a/modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_parsing_spec.rb+++ b/modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_parsing_spec.rb@@ -174,12 +174,18 @@ RSpec.describe API::V3::TimeEntries::TimeEntryRepresenter, "parsing" doendit "sets start_time" do+ user.pref[:time_zone] = "Asia/Tokyo"+time_entry = representer.from_hash(hash)- # timezone will be set by the UpdateAttributeService, so we do it manually here in the test- time_entry.time_zone = "Etc/UTC"+ # timezone on the TimeEntry would be set to the user's TimeZone via the SetAttribute service, so we need to+ # manually set it here+ time_entry.time_zone = "Asia/Tokyo"++ # We are sending in 12:30:00 UTC as the start time, in Tokyo time (for 2017-07-28) that equals+ # 21:30:00 in Japan Standard Time (JST), so the time should be set to 21:30- expect(time_entry.start_time).to eq((12 * 60) + 30) # 12:30+ expect(time_entry.start_time).to eq((21 * 60) + 30) # 12:30expect(time_entry.start_timestamp).to eq(DateTime.parse("2017-07-28T12:30:00Z"))expect(time_entry.end_timestamp).to eq(DateTime.parse("2017-07-28T17:30:00Z"))