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

Respect global time tracking hours-only setting in work item issues view

Chad Lavimoniere9aef1cfaeee0
diff --git a/frontend/src/app/shared/helpers/chronic_duration.spec.ts b/frontend/src/app/shared/helpers/chronic_duration.spec.ts
index aa48fc6f64b..95fc4fd3de3 100644
--- a/frontend/src/app/shared/helpers/chronic_duration.spec.ts
+++ b/frontend/src/app/shared/helpers/chronic_duration.spec.ts
@@ -382,6 +382,12 @@ describe('outputChronicDuration', () => {
).toBe('6 months 1 day 1 hour');
});
+ it('returns hours only if hoursOnly option specified, rounded to nearest hour', () => {
+ expect(outputChronicDuration(60 * 60 * 24 * 3 + 60 * 60 * 3, { hoursOnly: true })).toBe('75h');
+ expect(outputChronicDuration(4 * 3600 + 60 + 1, { hoursOnly: true })).toBe('4h');
+ expect(outputChronicDuration(5 * 3600, { hoursOnly: true })).toBe('5h');
+ });
+
describe('when the format is not specified', () => {
it('uses the default format', () => {
expect(outputChronicDuration(2 * 3600 + 20 * 60)).toBe('2 hrs 20 mins');
diff --git a/frontend/src/app/shared/helpers/chronic_duration.ts b/frontend/src/app/shared/helpers/chronic_duration.ts
index 2a5f75c53e3..6aca55e4245 100644
--- a/frontend/src/app/shared/helpers/chronic_duration.ts
+++ b/frontend/src/app/shared/helpers/chronic_duration.ts
@@ -64,6 +64,7 @@ export interface ChronicDurationOptions {
limitToHours?:boolean;
weeks?:boolean;
units?:number;
+ hoursOnly?:boolean;
}
type Dividers = Partial<Record<DurationUnit, string>> & { pluralize?:boolean; keepZero?:boolean};
@@ -282,6 +283,11 @@ export function parseChronicDuration(string:string, opts:ChronicDurationOptions
// Given an integer and an optional format,
// returns a formatted string representing elapsed time
export function outputChronicDuration(seconds:number, opts:ChronicDurationOptions = {}):string|null {
+ if (opts.hoursOnly) {
+ const hours = Math.round(seconds / 3600);
+ return `${hours}h`;
+ }
+
const units:Record<DurationUnit, number> = {
years: 0,
months: 0,