Currently, WindowStats class contains information about reset time and remaining amount. Could we add the time remaining until the reset?
This would be useful in some scenarios with user interaction (for example, Telegram bots).
I think time left before reset can be calculated in this way:
import time
from limits import parse
from limits.storage import MemoryStorage
from limits.strategies import FixedWindowRateLimiter
storage = MemoryStorage()
my_limiter = FixedWindowRateLimiter(storage)
limit = parse('1 per 30 seconds')
my_limiter.hit(limit, 'test')
window_stats = my_limiter.get_window_stats(limit, 'test')
time_before_reset = window_stats.reset_time - time.time()
print(time_before_reset)
@drygdryg sorry for the late response.
Perhaps I'm not seeing an obvious usecase - but why not compute the "time until reset" where you intend to use it based on reset_time ?
https://github.com/alisaifee/limits/blob/0946fdcd3b9509041a823d3bb1b63ea1de9ab6ee/limits/util.py#L36-L44
Expected Behaviour
Currently,
WindowStats
class contains information about reset time and remaining amount. Could we add the time remaining until the reset? This would be useful in some scenarios with user interaction (for example, Telegram bots).I think time left before reset can be calculated in this way: