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

exit early when no timezone is stored

Klaus Zandersb34f38464cfd
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index 659885a7d4e..b9e47e8d198 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -123,12 +123,14 @@ class TimeEntry < ApplicationRecord
def start_timestamp
return nil if start_time.blank?
+ return nil if time_zone.blank?
ActiveSupport::TimeZone[time_zone].local(spent_on.year, spent_on.month, spent_on.day, start_time / 60, start_time % 60)
end
def end_timestamp
return nil if end_time.blank?
+ return nil if time_zone.blank?
ActiveSupport::TimeZone[time_zone].local(spent_on.year, spent_on.month, spent_on.day, end_time / 60, end_time % 60)
end
diff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rb
index 1d14b1f2ee1..02afe96aa86 100644
--- a/modules/costs/spec/models/time_entry_spec.rb
+++ b/modules/costs/spec/models/time_entry_spec.rb
@@ -500,6 +500,11 @@ RSpec.describe TimeEntry do
expect(time_entry.start_timestamp).to be_nil
end
+ it "returns nil if timezone is nil" do
+ time_entry.time_zone = nil
+ expect(time_entry.start_timestamp).to be_nil
+ end
+
it "generates a proper timestamp from the stored information" do
time_entry.start_time = 14 * 60
time_entry.spent_on = Date.new(2024, 12, 24)
@@ -515,6 +520,11 @@ RSpec.describe TimeEntry do
expect(time_entry.end_timestamp).to be_nil
end
+ it "returns nil if timezone is nil" do
+ time_entry.time_zone = nil
+ expect(time_entry.end_timestamp).to be_nil
+ end
+
it "generates a proper timestamp from the stored information" do
time_entry.end_time = 14 * 60
time_entry.spent_on = Date.new(2024, 12, 24)