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

Merge branch 'dev' into feature/61896-overview-of-time-logged-per-day-per-user-in-pdf-timesheet

as-opd29d05ef1773
diff --cc lib/chronic_duration.rb
index 474b9b02035,f3a03d6ef8a..de6db62414d
--- a/lib/chronic_duration.rb
+++ b/lib/chronic_duration.rb
@@@ -102,14 -100,9 +100,14 @@@ module ChronicDuratio
month = days_per_month * day
year = SECONDS_PER_YEAR
- if opts[:format] == :hours_only
+ if %i[hours_only hours_and_minutes].include?(opts[:format])
hours = seconds / 3600.0
seconds = 0
+ elsif opts[:format] == :hours_colon_minutes
+ hours = (seconds / hour).to_i
+ minutes = (seconds % hour / minute).to_i
+ minutes += 1 if (seconds % hour % minute) > 0
+ seconds = 0
elsif seconds >= SECONDS_PER_YEAR && seconds % year < seconds % month
years = seconds / year
months = seconds % year / month
@@@ -189,19 -182,11 +187,24 @@@
hours = hours.round(2)
hours_int = hours.to_i
hours = 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.floor
+ when :hours_colon_minutes
+ dividers = {
+ hours: ":", minutes: "", keep_zero: true
+ }
+ process = lambda do |str|
+ # Pad zeros on minutes
+ divider = ":"
+ result = str.split(divider).each_with_index.map do |n, index|
+ n.rjust(index > 0 ? 2 : 1, "0")
+ end.join(divider)
+ "#{result} h"
+ end
+ joiner = ""
when :chrono
dividers = {
years: ":", months: ":", weeks: ":", days: ":", hours: ":", minutes: ":", seconds: ":", keep_zero: true
diff --cc spec/lib/chronic_duration_spec.rb
index c2f60cdc242,a1f5f9d75ce..b577af35550
--- a/spec/lib/chronic_duration_spec.rb
+++ b/spec/lib/chronic_duration_spec.rb
@@@ -31,7 -31,7 +31,7 @@@
require "rspec_helper"
require "chronic_duration"
- INACCURATE_FORMATS = %i[days_and_hours hours_only hours_colon_minutes].freeze
-INACCURATE_FORMATS = %i[days_and_hours hours_only hours_and_minutes].freeze
++INACCURATE_FORMATS = %i[days_and_hours hours_only hours_and_minutes hours_colon_minutes].freeze
RSpec.describe ChronicDuration do
describe ".parse" do
@@@ -151,7 -151,7 +151,8 @@@
long: "1 minute 20 seconds",
days_and_hours: "0.02h",
hours_only: "0.02h",
+ hours_and_minutes: "1m",
+ hours_colon_minutes: "0:02 h",
chrono: "1:20"
},
(60 + 20.51) =>
@@@ -162,7 -162,7 +163,8 @@@
long: "1 minute 20.51 seconds",
days_and_hours: "0.02h",
hours_only: "0.02h",
+ hours_and_minutes: "1m",
+ hours_colon_minutes: "0:02 h",
chrono: "1:20.51"
},
(60 + 20.51928) =>
@@@ -173,7 -173,7 +175,8 @@@
long: "1 minute 20.51928 seconds",
days_and_hours: "0.02h",
hours_only: "0.02h",
+ hours_and_minutes: "1m",
+ hours_colon_minutes: "0:02 h",
chrono: "1:20.51928"
},
((4 * 3600) + 60 + 1) =>
@@@ -184,7 -184,7 +187,8 @@@
long: "4 hours 1 minute 1 second",
days_and_hours: "4.02h",
hours_only: "4.02h",
+ hours_and_minutes: "4h 1m",
+ hours_colon_minutes: "4:02 h",
chrono: "4:01:01"
},
((2 * 3600) + (20 * 60)) =>
@@@ -195,7 -195,7 +199,8 @@@
long: "2 hours 20 minutes",
days_and_hours: "2.33h",
hours_only: "2.33h",
+ hours_and_minutes: "2h 20m",
+ hours_colon_minutes: "2:20 h",
chrono: "2:20:00"
},
((8 * 24 * 3600) + (3 * 3600) + (30 * 60)) =>
@@@ -206,7 -206,7 +211,8 @@@
long: "8 days 3 hours 30 minutes",
days_and_hours: "8d 3.5h",
hours_only: "195.5h",
+ hours_and_minutes: "195h 30m",
+ hours_colon_minutes: "195:30 h",
chrono: "8:03:30:00"
},
((6 * 30 * 24 * 3600) + (24 * 3600)) =>
@@@ -217,7 -217,7 +223,8 @@@
long: "6 months 1 day",
days_and_hours: "181d 0h",
hours_only: "4344h",
+ hours_and_minutes: "4344h",
+ hours_colon_minutes: "4344:00 h",
chrono: "6:01:00:00:00" # Yuck. FIXME
},
((365.25 * 24 * 3600) + (24 * 3600)).to_i =>
@@@ -228,7 -228,7 +235,8 @@@
long: "1 year 1 day",
days_and_hours: "366d 0h",
hours_only: "8790h",
+ hours_and_minutes: "8790h",
+ hours_colon_minutes: "8790:00 h",
chrono: "1:00:01:00:00:00"
},
((3 * 365.25 * 24 * 3600) + (24 * 3600)).to_i =>
@@@ -239,7 -239,7 +247,8 @@@
long: "3 years 1 day",
days_and_hours: "1096d 0h",
hours_only: "26322h",
+ hours_and_minutes: "26322h",
+ hours_colon_minutes: "26322:00 h",
chrono: "3:00:01:00:00:00"
},
((6 * 365.25 * 24 * 3600) + (3 * 3600)).to_i =>
@@@ -250,7 -250,7 +259,8 @@@
long: "6 years 3 hours",
days_and_hours: "2191d 3h",
hours_only: "52599h",
+ hours_and_minutes: "52599h",
+ hours_colon_minutes: "52599:00 h",
chrono: "6:00:00:03:00:00"
},
(3600 * 24 * 30 * 18) =>
@@@ -261,7 -261,7 +271,8 @@@
long: "18 months",
days_and_hours: "540d 0h",
hours_only: "12960h",
+ hours_and_minutes: "12960h",
+ hours_colon_minutes: "12960:00 h",
chrono: "18:00:00:00:00"
}
}