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

add functionality to chronic duration to parse 8:15 to 8hours 15minutes instead of 8minutes 15seconds

Klaus Zanders4da7e4b8cade
diff --git a/frontend/src/app/shared/helpers/chronic_duration.js b/frontend/src/app/shared/helpers/chronic_duration.js
index 9689a5390db..de4fac624ff 100644
--- a/frontend/src/app/shared/helpers/chronic_duration.js
+++ b/frontend/src/app/shared/helpers/chronic_duration.js
@@ -143,8 +143,14 @@ function calculateFromWords(string, opts) {
}
// Parse 3:41:59 and return 3 hours 41 minutes 59 seconds
-function filterByType(string) {
- const chronoUnitsList = DURATION_UNITS_LIST.filter((v) => v !== 'weeks');
+function filterByType(string, opts) {
+ const chronoUnitsList = DURATION_UNITS_LIST.filter(function (value) {
+ if (value === "weeks") { return false }
+ if (opts.ignoreSecondsWhenColonSeperated && value === "seconds") { return false }
+
+ return true
+ });
+
if (
string
.replace(/ +/g, '')
@@ -196,7 +202,7 @@ function filterThroughWhiteList(string, opts) {
function cleanup(string, opts) {
let res = string.toLowerCase();
- res = filterByType(res);
+ res = filterByType(res, opts);
res = res
.replace(FLOAT_MATCHER, (n) => ` ${n} `)
.replace(/ +/g, ' ')
diff --git a/frontend/src/app/shared/helpers/chronic_duration.spec.ts b/frontend/src/app/shared/helpers/chronic_duration.spec.ts
index ae44d959927..8946fbb9848 100644
--- a/frontend/src/app/shared/helpers/chronic_duration.spec.ts
+++ b/frontend/src/app/shared/helpers/chronic_duration.spec.ts
@@ -151,6 +151,17 @@ describe('parseChronicDuration', () => {
);
});
});
+
+ describe('with .ignoreSecondsWhenColonSeperated param', () => {
+ it('parses 8:15 to 8 hours 15 minutes when seconds are ignored', () => {
+ expect(parseChronicDuration('8:15', { ignoreSecondsWhenColonSeperated: true })).toBe(8 * 3600 + 15 * 60);
+ });
+
+ it('parses 8:15 to 8 minutes 15 seconds when seconds are not ignored', () => {
+ expect(parseChronicDuration('8:15')).toBe(8 * 60 + 15);
+ });
+
+ });
});
describe('outputChronicDuration', () => {