Skip to content

Commit

Permalink
Fix timer button rolling over after 24h (#13148)
Browse files Browse the repository at this point in the history
* Fix timer button rolling over after 24h

* Use padStart function.

---------

Co-authored-by: Dombi Attila <[email protected]>
  • Loading branch information
oliverguenther and dombesz authored Jul 17, 2023
1 parent 12eb324 commit 0c9ffc7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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(':');
}
14 changes: 14 additions & 0 deletions modules/costs/spec/features/timer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@

it_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' do
wp_view_a.visit!
timer_button.expect_visible
Expand Down
4 changes: 4 additions & 0 deletions spec/support/components/work_packages/timer_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def expect_inactive
expect(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 visible
expect(page).to have_selector('op-wp-timer-button')
Expand Down

0 comments on commit 0c9ffc7

Please sign in to comment.