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
add time zone for time entries
Klaus Zandersc785d0a68114
diff --git a/db/migrate/20241125104347_add_timezone_identifier_to_time_entry.rb b/db/migrate/20241125104347_add_timezone_identifier_to_time_entry.rbnew file mode 100644index 00000000000..44520412261--- /dev/null+++ b/db/migrate/20241125104347_add_timezone_identifier_to_time_entry.rb@@ -0,0 +1,6 @@+class AddTimezoneIdentifierToTimeEntry < ActiveRecord::Migration[7.1]+ def change+ add_column :time_entries, :time_zone, :string+ add_column :time_entry_journals, :time_zone, :string+ end+enddiff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rbindex 962f12750a5..659885a7d4e 100644--- a/modules/costs/app/models/time_entry.rb+++ b/modules/costs/app/models/time_entry.rb@@ -121,6 +121,18 @@ class TimeEntry < ApplicationRecord(user_id == usr.id && usr.allowed_in_project?(:view_own_hourly_rate, project))end+ def start_timestamp+ return nil if start_time.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?++ ActiveSupport::TimeZone[time_zone].local(spent_on.year, spent_on.month, spent_on.day, end_time / 60, end_time % 60)+ end+class << selfdef can_track_start_and_end_time?(_project: nil)OpenProject::FeatureDecisions.track_start_and_end_times_for_time_entries_active? &&diff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rbindex 521288515a6..1d14b1f2ee1 100644--- a/modules/costs/spec/models/time_entry_spec.rb+++ b/modules/costs/spec/models/time_entry_spec.rb@@ -62,6 +62,7 @@ RSpec.describe TimeEntry dostart_time: start_time,end_time: start_time + (hours * 60).to_i,user:,+ time_zone: user.time_zone,rate: hourly_one,comments: "lorem")end@@ -493,6 +494,36 @@ RSpec.describe TimeEntry doendend+ describe "#start_timestamp" do+ it "returns nil if start_time is nil" do+ time_entry.start_time = 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)+ time_entry.time_zone = "America/Los_Angeles"++ expect(time_entry.start_timestamp.iso8601).to eq("2024-12-24T14:00:00-08:00")+ end+ end++ describe "#end_timestamp" do+ it "returns nil if end_time is nil" do+ time_entry.end_time = 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)+ time_entry.time_zone = "America/Los_Angeles"++ expect(time_entry.end_timestamp.iso8601).to eq("2024-12-24T14:00:00-08:00")+ end+ end+describe ".must_track_start_and_end_time?" docontext "with the feature flag enabled", with_flag: { track_start_and_end_times_for_time_entries: true } docontext "with the allow setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do