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
Fix timer button rolling over after 24h (#13148)
Oliver Günther0c9ffc7767b0
diff --git a/frontend/src/app/features/work-packages/components/wp-timer-button/time-formatter.helper.ts b/frontend/src/app/features/work-packages/components/wp-timer-button/time-formatter.helper.tsindex 4cef4644263..dfb18f501a6 100644--- a/frontend/src/app/features/work-packages/components/wp-timer-button/time-formatter.helper.ts+++ b/frontend/src/app/features/work-packages/components/wp-timer-button/time-formatter.helper.ts@@ -1,9 +1,21 @@import * as moment from 'moment/moment';+function paddedNumber(input:number):string {+ return input.toString().padStart(2, '0');+}+export function formatElapsedTime(startTime:string):string {const start = moment(startTime);const now = moment();- const offset = moment(now).diff(start);+ const duration = now.diff(start, 'seconds');++ const hours = Math.floor(duration / 3600);+ const minutes = Math.floor((duration - (hours * 3600)) / 60);+ const seconds = duration - (hours * 3600) - (minutes * 60);- return moment.utc(offset).format('HH:mm:ss');+ return [+ paddedNumber(hours),+ paddedNumber(minutes),+ paddedNumber(seconds),+ ].join(':');}diff --git a/modules/costs/spec/features/timer_spec.rb b/modules/costs/spec/features/timer_spec.rbindex 54c313616b1..5c4ce8447bd 100644--- a/modules/costs/spec/features/timer_spec.rb+++ b/modules/costs/spec/features/timer_spec.rb@@ -130,6 +130,20 @@ RSpec.describe 'Work Package timer', js: true doit_behaves_like 'allows time tracking'+ context 'when an old timer exists' do+ let!(:active_timer) do+ Timecop.travel(2.days.ago) do+ create(:time_entry, project:, work_package: work_package_a, user:, ongoing: true)+ end+ end++ it 'correctly shows active timers > 24 hours' do+ wp_view_a.visit!+ timer_button.expect_visible+ timer_button.expect_time /48:0\d:\d+/+ end+ end+it 'correctly handles timers in multiple tabs' dowp_view_a.visit!timer_button.expect_visiblediff --git a/spec/support/components/work_packages/timer_button.rb b/spec/support/components/work_packages/timer_button.rbindex bba258c17bc..8f64550ba40 100644--- a/spec/support/components/work_packages/timer_button.rb+++ b/spec/support/components/work_packages/timer_button.rb@@ -41,6 +41,10 @@ module Componentsexpect(page).to have_selector('[data-qa-selector="timer-inactive"]', wait: 10)end+ def expect_time(text)+ expect(page).to have_selector('[data-qa-selector="timer-active"]', wait: 10, text:)+ end+def expect_visible(visible: true)if visibleexpect(page).to have_selector('op-wp-timer-button')