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
remove end_time, add timezone
Klaus Zanders54b2f9a3489d
diff --git a/db/migrate/20241125104347_add_timezone_identifier_to_time_entry.rb b/db/migrate/20241125104347_add_timezone_identifier_to_time_entry.rbindex 44520412261..b75120ef873 100644--- a/db/migrate/20241125104347_add_timezone_identifier_to_time_entry.rb+++ b/db/migrate/20241125104347_add_timezone_identifier_to_time_entry.rb@@ -1,6 +1,13 @@class AddTimezoneIdentifierToTimeEntry < ActiveRecord::Migration[7.1]def change- add_column :time_entries, :time_zone, :string- add_column :time_entry_journals, :time_zone, :string+ change_table :time_entries, bulk: true do |t|+ t.string :time_zone, null: true+ t.remove :end_time, type: :integer+ end++ change_table :time_entry_journals, bulk: true do |t|+ t.string :time_zone, null: true+ t.remove :end_time, type: :integer+ endendenddiff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rbindex b9e47e8d198..8bbeed8d183 100644--- a/modules/costs/app/models/time_entry.rb+++ b/modules/costs/app/models/time_entry.rb@@ -47,7 +47,7 @@ class TimeEntry < ApplicationRecordvalidates_presence_of :hours, if: -> { !ongoing? }validates_numericality_of :hours, allow_nil: true, message: :invalid- validates :start_time, :end_time,+ validates :start_time, :hours,presence: true,if: -> { TimeEntry.must_track_start_and_end_time? }@@ -55,15 +55,6 @@ class TimeEntry < ApplicationRecordnumericality: { only_integer: true, greater_than_or_equal_to: MIN_TIME, less_than_or_equal_to: MAX_TIME },allow_blank: true- validates :end_time,- numericality: {- only_integer: true,- greater_than: ->(te) { te.start_time.to_i },- less_than_or_equal_to: MAX_TIME- # TODO: nice error message- },- allow_blank: true-scope :on_work_packages, ->(work_packages) { where(work_package_id: work_packages) }extend ::TimeEntries::TimeEntryScopes@@ -129,10 +120,11 @@ class TimeEntry < ApplicationRecordenddef end_timestamp- return nil if end_time.blank?+ return nil if start_time.blank?return nil if time_zone.blank?+ return nil if hours.blank?- ActiveSupport::TimeZone[time_zone].local(spent_on.year, spent_on.month, spent_on.day, end_time / 60, end_time % 60)+ start_timestamp + hours.hoursendclass << selfdiff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rbindex 02afe96aa86..8f3fa58884d 100644--- a/modules/costs/spec/models/time_entry_spec.rb+++ b/modules/costs/spec/models/time_entry_spec.rb@@ -60,7 +60,6 @@ RSpec.describe TimeEntry dospent_on: date,hours:,start_time: start_time,- end_time: start_time + (hours * 60).to_i,user:,time_zone: user.time_zone,rate: hourly_one,@@ -436,58 +435,19 @@ RSpec.describe TimeEntry doendend- describe "end_time" do- it "allows blank values" do- time_entry.end_time = nil- expect(time_entry).to be_valid- end-- it "allows integer values between 0 and 1439" do- time_entry.end_time = 1337- expect(time_entry).to be_valid- end-- it "does not allow values > 1439" do- time_entry.end_time = 1440- expect(time_entry).not_to be_valid- end-- it "does not allow non integer values" do- time_entry.end_time = 1.5- expect(time_entry).not_to be_valid- end-- it "does not allow negative values" do- time_entry.end_time = -42- expect(time_entry).not_to be_valid- end- end-describe "start_time and end_time" do- it "does not allow end times smaller than the start time" do- time_entry.start_time = 10 * 60- time_entry.end_time = 8 * 60-- expect(time_entry).not_to be_valid- end-- context "when enforcing start and end times" do+ context "when enforcing times" dobefore doallow(described_class).to receive(:must_track_start_and_end_time?).and_return(true)endit "validates that both values are present" dotime_entry.start_time = nil- time_entry.end_time = nilexpect(time_entry).not_to be_validtime_entry.start_time = 10 * 60- expect(time_entry).not_to be_valid-- time_entry.end_time = 12 * 60-expect(time_entry).to be_validendend@@ -515,8 +475,8 @@ RSpec.describe TimeEntry doenddescribe "#end_timestamp" do- it "returns nil if end_time is nil" do- time_entry.end_time = nil+ it "returns nil if start_time is nil" do+ time_entry.start_time = nilexpect(time_entry.end_timestamp).to be_nilend@@ -526,11 +486,12 @@ RSpec.describe TimeEntry doendit "generates a proper timestamp from the stored information" do- time_entry.end_time = 14 * 60+ time_entry.start_time = 8 * 60+ time_entry.hours = 2.5time_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")+ expect(time_entry.end_timestamp.iso8601).to eq("2024-12-24T10:30:00-08:00")endend