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
Display durations as days and hours
Christophe Bliard495aa9cc774d
diff --git a/app/services/duration_converter.rb b/app/services/duration_converter.rbindex 0d6ddb66b04..e1f7a921292 100644--- a/app/services/duration_converter.rb+++ b/app/services/duration_converter.rb@@ -109,22 +109,10 @@ class DurationConverterseconds_overflow = seconds % 60seconds_to_the_nearest_minute = seconds - seconds_overflow- # return "0 h" if parsing 0.- # ChronicDuration returns nil when parsing 0.- # By default, its unit is seconds and if we were- # keeping zeroes, we'd format this as "0 secs".- #- # We want to override this behavior.- if ChronicDuration.output(seconds_to_the_nearest_minute,- default_unit: "hours",- **duration_length_options).nil?- "0h"- else- ChronicDuration.output(seconds_to_the_nearest_minute,- default_unit: "hours",- format: :short,- **duration_length_options)- end+ # :days_and_hours format return "0h" when parsing 0.+ ChronicDuration.output(seconds_to_the_nearest_minute,+ format: :days_and_hours,+ **duration_length_options)endprivatediff --git a/frontend/src/app/core/datetime/timezone.service.ts b/frontend/src/app/core/datetime/timezone.service.tsindex 8900b7e9edc..9e7e8da0ceb 100644--- a/frontend/src/app/core/datetime/timezone.service.ts+++ b/frontend/src/app/core/datetime/timezone.service.ts@@ -149,7 +149,7 @@ export class TimezoneService {}public formattedChronicDuration(durationString:string, opts = {- format: 'short',+ format: 'daysAndHours',hoursPerDay: this.configurationService.hoursPerDay(),// daysPerWeek is solely a convenience unit for the user's comprehension.// It's not an accepted unit by chronicDuration. daysPerMonth is the valuediff --git a/modules/costs/spec/features/time_entries_spec.rb b/modules/costs/spec/features/time_entries_spec.rbindex cb0a76abe21..d82dcbaadeb 100644--- a/modules/costs/spec/features/time_entries_spec.rb+++ b/modules/costs/spec/features/time_entries_spec.rb@@ -73,8 +73,8 @@ RSpec.describe "Work Package table cost entries", :js doparent_row = wp_table.row(parent)wp_row = wp_table.row(work_package)- expect(parent_row).to have_css(".inline-edit--container.spentTime", text: "1d 4h 30m")- expect(wp_row).to have_css(".inline-edit--container.spentTime", text: "2h 30m")+ expect(parent_row).to have_css(".inline-edit--container.spentTime", text: "1d 4.5h")+ expect(wp_row).to have_css(".inline-edit--container.spentTime", text: "2.5h")endit "creates an activity" dodiff --git a/spec/features/activities/work_package_activity_spec.rb b/spec/features/activities/work_package_activity_spec.rbindex 3eab179c792..59c62781ada 100644--- a/spec/features/activities/work_package_activity_spec.rb+++ b/spec/features/activities/work_package_activity_spec.rb@@ -52,7 +52,7 @@ RSpec.describe "Work package activity", :js, :with_cuprite dobefore dowp_page = Pages::FullWorkPackage.new(parent)wp_page.visit!- wp_page.update_attributes estimatedTime: "10" # rubocop:disable Rails/ActiveRecordAliases+ wp_page.update_attributes estimatedTime: "100" # rubocop:disable Rails/ActiveRecordAliaseswp_page.expect_and_dismiss_toaster(message: "Successful update.")wp_page.update_attributes remainingTime: "5" # rubocop:disable Rails/ActiveRecordAliaseswp_page.expect_and_dismiss_toaster(message: "Successful update.")@@ -60,12 +60,12 @@ RSpec.describe "Work package activity", :js, :with_cuprite doit "displays changed attributes in the activity tab", :aggregate_failures dowithin("activity-entry", text: admin.name) do- expect(page).to have_list_item(text: "% Complete set to 50%")- expect(page).to have_list_item(text: "Work set to 1d 2h")+ expect(page).to have_list_item(text: "% Complete set to 95%")+ expect(page).to have_list_item(text: "Work set to 12d 4h")expect(page).to have_list_item(text: "Remaining work set to 5h")- expect(page).to have_list_item(text: "Total work set to 2d 4h")- expect(page).to have_list_item(text: "Total remaining work set to 1d")- expect(page).to have_list_item(text: "Total % complete set to 60%")+ expect(page).to have_list_item(text: "Total work set to 13d 6h")+ expect(page).to have_list_item(text: "Total remaining work set to 1d 0h")+ expect(page).to have_list_item(text: "Total % complete set to 93%")endendenddiff --git a/spec/features/work_packages/index_sums_spec.rb b/spec/features/work_packages/index_sums_spec.rbindex 896ea730cb8..08ce62e62e5 100644--- a/spec/features/work_packages/index_sums_spec.rb+++ b/spec/features/work_packages/index_sums_spec.rb@@ -147,7 +147,7 @@ RSpec.describe "Work package index sums", :js doaggregate_failures dowithin(:row, "Total sum") do |row|expect(row).to have_css(".estimatedTime", text: "3d 1h")- expect(row).to have_css(".remainingTime", text: "1d 4h 30m")+ expect(row).to have_css(".remainingTime", text: "1d 4.5h")expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: "12")expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: "13.2")expect(row).to have_css(".laborCosts", text: "15.00 EUR")@@ -165,7 +165,7 @@ RSpec.describe "Work package index sums", :js doaggregate_failures dowithin(:row, "Total sum") do |row|expect(row).to have_css(".estimatedTime", text: "4d 3h")- expect(row).to have_css(".remainingTime", text: "2d 3h 30m")+ expect(row).to have_css(".remainingTime", text: "2d 3.5h")expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: "12")expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: "13.2")expect(row).to have_css(".laborCosts", text: "15.00 EUR")@@ -196,7 +196,7 @@ RSpec.describe "Work package index sums", :js do# Second status rowaggregate_failures doexpect(second_sum_row).to have_css(".estimatedTime", text: "1d 7h")- expect(second_sum_row).to have_css(".remainingTime", text: "7h 30m")+ expect(second_sum_row).to have_css(".remainingTime", text: "7.5h")expect(second_sum_row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: "7")expect(second_sum_row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: "7.7")expect(second_sum_row).to have_css(".laborCosts", text: "", exact_text: true)@@ -208,7 +208,7 @@ RSpec.describe "Work package index sums", :js doaggregate_failures dowithin(:row, "Total sum") do |row|expect(row).to have_css(".estimatedTime", text: "4d 3h")- expect(row).to have_css(".remainingTime", text: "2d 3h 30m")+ expect(row).to have_css(".remainingTime", text: "2d 3.5h")expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: "12")expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: "13.2")expect(row).to have_css(".laborCosts", text: "15.00 EUR")@@ -282,7 +282,7 @@ RSpec.describe "Work package index sums", :js do# Expect the total sums row without filteringaggregate_failures dowithin(:row, "Total sum") do |row|- expect(row).to have_css(".estimatedTime", text: "1w 1d 2h")+ expect(row).to have_css(".estimatedTime", text: "6d 2h")expect(row).to have_css(".remainingTime", text: "3d 1h")expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: "24")expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: "26.4")@@ -340,7 +340,7 @@ RSpec.describe "Work package index sums", :js do# Second status rowaggregate_failures doexpect(second_sum_row).to have_css(".estimatedTime", text: "1d 7h")- expect(second_sum_row).to have_css(".remainingTime", text: "7h 30m")+ expect(second_sum_row).to have_css(".remainingTime", text: "7.5h")expect(second_sum_row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: "7")expect(second_sum_row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: "7.7")expect(second_sum_row).to have_css(".laborCosts", text: "", exact_text: true)@@ -352,7 +352,7 @@ RSpec.describe "Work package index sums", :js doaggregate_failures dowithin(:row, "Total sum") do |row|expect(row).to have_css(".estimatedTime", text: "3d 1h")- expect(row).to have_css(".remainingTime", text: "1d 4h 30m")+ expect(row).to have_css(".remainingTime", text: "1d 4.5h")expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: "12")expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: "13.2")expect(row).to have_css(".laborCosts", text: "15.00 EUR")diff --git a/spec/models/work_package_spec.rb b/spec/models/work_package_spec.rbindex e8885efdf74..69970138cd6 100644--- a/spec/models/work_package_spec.rb+++ b/spec/models/work_package_spec.rb@@ -799,7 +799,7 @@ RSpec.describe WorkPackage doexpect(work_package.remaining_hours).to eq(1.4)end- it "allows hours like '3d 1h 30m'" do+ it "allows hours like '3d 1.5h 30m'" dowork_package.remaining_hours = "3d 1h 30m"expect(work_package).to be_validexpect(work_package.remaining_hours).to eq((3 * 8) + 1.5)diff --git a/spec/services/duration_converter_spec.rb b/spec/services/duration_converter_spec.rbindex ae41cc833a2..a20594a4e00 100644--- a/spec/services/duration_converter_spec.rb+++ b/spec/services/duration_converter_spec.rb@@ -62,16 +62,22 @@ RSpec.describe DurationConverter doexpect(described_class.output(0)).to eq("0h")end- it "works with ChronicDuration defaults otherwise in :short format" do+ it "works with ChronicDuration defaults otherwise in :days_and_hours format" doexpect(described_class.output(5.75))- .to eq("5h 45m")+ .to eq("5.75h")+ expect(described_class.output(5.754321))+ .to eq("5.75h")+ expect(described_class.output(8))+ .to eq("1d 0h")+ expect(described_class.output(804))+ .to eq("100d 4h")end- it "ignores seconds and keep the nearest minute" do+ it "ignores seconds and keep the nearest minute, displayed as hours" doexpect(described_class.output(0.28))- .to eq("17m")+ .to eq("0.28h")expect(described_class.output(2.23))- .to eq("2h 14m")+ .to eq("2.23h")endendend