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
show totals for the time range under the calendar
Klaus Zanders4a98bcaaffa5
diff --git a/lib/chronic_duration.rb b/lib/chronic_duration.rbindex 94500124811..5e97dc49de6 100644--- a/lib/chronic_duration.rb+++ b/lib/chronic_duration.rb@@ -102,7 +102,7 @@ module ChronicDurationmonth = days_per_month * dayyear = SECONDS_PER_YEAR- if opts[:format] == :hours_only+ if %i[hours_only hours_and_minutes].include?(opts[:format])hours = seconds / 3600.0seconds = 0elsif seconds >= SECONDS_PER_YEAR && seconds % year < seconds % month@@ -184,6 +184,11 @@ module ChronicDurationhours = hours.round(2)hours_int = hours.to_ihours = hours_int if hours - hours_int == 0 # if hours end with .0+ when :hours_and_minutes+ dividers = { hours: "h", minutes: "m", keep_zero: false }++ minutes = ((hours % 1) * 60).round+ hours = hours.floorwhen :chronodividers = {years: ":", months: ":", weeks: ":", days: ":", hours: ":", minutes: ":", seconds: ":", keep_zero: truediff --git a/modules/costs/app/components/my/time_tracking/calendar_component.html.erb b/modules/costs/app/components/my/time_tracking/calendar_component.html.erbindex 2f77e251365..fd8861bdbae 100644--- a/modules/costs/app/components/my/time_tracking/calendar_component.html.erb+++ b/modules/costs/app/components/my/time_tracking/calendar_component.html.erb@@ -22,4 +22,6 @@end %><div data-my--time-tracking-target="calendar"></div>++ <div><%= total_hours %></div><%- end %>diff --git a/modules/costs/app/components/my/time_tracking/calendar_component.rb b/modules/costs/app/components/my/time_tracking/calendar_component.rbindex c0a47b806af..489bb5c706c 100644--- a/modules/costs/app/components/my/time_tracking/calendar_component.rb+++ b/modules/costs/app/components/my/time_tracking/calendar_component.rb@@ -110,6 +110,13 @@ module My{ href: my_time_tracking_month_path(date: date + 1.month), aria: { label: I18n.t(:label_next_month) } }endend++ def total_hours+ total_hours = time_entries.sum(&:hours).round(2)+ total_str = DurationConverter.output(total_hours, format: :hours_and_minutes)++ I18n.t(mode, scope: "total_times", hours: total_str)+ endendendenddiff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.ymlindex f1750245023..d9908438e7b 100644--- a/modules/costs/config/locales/en.yml+++ b/modules/costs/config/locales/en.yml@@ -204,6 +204,11 @@ en:week: "week"+ total_times:+ week: "Week Total: %{hours}"+ month: "Month Total: %{hours}"+ day: "Day Total: %{hours}"+api_v3:errors:validation:diff --git a/spec/lib/chronic_duration_spec.rb b/spec/lib/chronic_duration_spec.rbindex b47039765c5..a1f5f9d75ce 100644--- a/spec/lib/chronic_duration_spec.rb+++ b/spec/lib/chronic_duration_spec.rb@@ -31,7 +31,7 @@require "rspec_helper"require "chronic_duration"-INACCURATE_FORMATS = %i[days_and_hours hours_only].freeze+INACCURATE_FORMATS = %i[days_and_hours hours_only hours_and_minutes].freezeRSpec.describe ChronicDuration dodescribe ".parse" do@@ -151,6 +151,7 @@ RSpec.describe ChronicDuration dolong: "1 minute 20 seconds",days_and_hours: "0.02h",hours_only: "0.02h",+ hours_and_minutes: "1m",chrono: "1:20"},(60 + 20.51) =>@@ -161,6 +162,7 @@ RSpec.describe ChronicDuration dolong: "1 minute 20.51 seconds",days_and_hours: "0.02h",hours_only: "0.02h",+ hours_and_minutes: "1m",chrono: "1:20.51"},(60 + 20.51928) =>@@ -171,6 +173,7 @@ RSpec.describe ChronicDuration dolong: "1 minute 20.51928 seconds",days_and_hours: "0.02h",hours_only: "0.02h",+ hours_and_minutes: "1m",chrono: "1:20.51928"},((4 * 3600) + 60 + 1) =>@@ -181,6 +184,7 @@ RSpec.describe ChronicDuration dolong: "4 hours 1 minute 1 second",days_and_hours: "4.02h",hours_only: "4.02h",+ hours_and_minutes: "4h 1m",chrono: "4:01:01"},((2 * 3600) + (20 * 60)) =>@@ -191,6 +195,7 @@ RSpec.describe ChronicDuration dolong: "2 hours 20 minutes",days_and_hours: "2.33h",hours_only: "2.33h",+ hours_and_minutes: "2h 20m",chrono: "2:20:00"},((8 * 24 * 3600) + (3 * 3600) + (30 * 60)) =>@@ -201,6 +206,7 @@ RSpec.describe ChronicDuration dolong: "8 days 3 hours 30 minutes",days_and_hours: "8d 3.5h",hours_only: "195.5h",+ hours_and_minutes: "195h 30m",chrono: "8:03:30:00"},((6 * 30 * 24 * 3600) + (24 * 3600)) =>@@ -211,6 +217,7 @@ RSpec.describe ChronicDuration dolong: "6 months 1 day",days_and_hours: "181d 0h",hours_only: "4344h",+ hours_and_minutes: "4344h",chrono: "6:01:00:00:00" # Yuck. FIXME},((365.25 * 24 * 3600) + (24 * 3600)).to_i =>@@ -221,6 +228,7 @@ RSpec.describe ChronicDuration dolong: "1 year 1 day",days_and_hours: "366d 0h",hours_only: "8790h",+ hours_and_minutes: "8790h",chrono: "1:00:01:00:00:00"},((3 * 365.25 * 24 * 3600) + (24 * 3600)).to_i =>@@ -231,6 +239,7 @@ RSpec.describe ChronicDuration dolong: "3 years 1 day",days_and_hours: "1096d 0h",hours_only: "26322h",+ hours_and_minutes: "26322h",chrono: "3:00:01:00:00:00"},((6 * 365.25 * 24 * 3600) + (3 * 3600)).to_i =>@@ -241,6 +250,7 @@ RSpec.describe ChronicDuration dolong: "6 years 3 hours",days_and_hours: "2191d 3h",hours_only: "52599h",+ hours_and_minutes: "52599h",chrono: "6:00:00:03:00:00"},(3600 * 24 * 30 * 18) =>@@ -251,6 +261,7 @@ RSpec.describe ChronicDuration dolong: "18 months",days_and_hours: "540d 0h",hours_only: "12960h",+ hours_and_minutes: "12960h",chrono: "18:00:00:00:00"}}