CountdownTimer.addTime() seems to be subtracting time instead

Hello all,
This problem may be a result of me misunderstanding the functionality of CountdownTimer.addTime(), but it seems that the method is actually subtracting time from the timer. CountdownTimer.add() works as expected, but that is evidently the deprecated method:

from psychopy.core import CountdownTimer

timer = CountdownTimer(5)
print(timer.getTime()) # Expected: ~5s; Output: 4.999792290996993s
print(timer.getTime()) # Expected: ~6s; Output: 3.9997760410042247s

timer2 = CountdownTimer(5)
print(timer2.getTime()) # Expected: ~5s; Output: 4.999974125006702
print(timer2.getTime()) # Expected: ~6s; Output: 5.999952666999889

What gives?

Edit: To work around this, I’ve just been adding negative time to the timer, but once again I’m not sure if this is the desired behavior.

Working as intended but deeply counterintuitive, I’m afraid.

CountdownTimer is still based on the Clock object. What it’s really doing is creating a clock that counts up normally, but it is subtracting the current value of the clock from a constant that is the maximum value of the timer (five seconds, in your case).

So, “addTime” is adding to the Clock ‘inside’ the CountdownTimer therefore jumping the timer ‘forward’ one second and decreasing the displayed time. The other problem is that “add” is kind of counterintuitive and deprecated (meaning it’s no longer intended to be used). If you were using a normal Clock, ‘add’ would decrease the displayed time by that amount because it adds not to the clock itself but to the start time of the clock. That weirdness is why it’s not supposed to be used. However, because you’re using a CountdownTimer, that increases the displayed time by that amount instead.

It’s a confluence of two counterintuitive things, the way “add” and “addTime” work and the way that CountdownTimer is just a flipped Clock, but everything is doing what it’s supposed to do. It’s just that CountdownTimer doesn’t have it’s own separate “addTime” function.

Thanks @Catyre and I’ve pulled in your fix

1 Like