The lines above are identical to the ones you can find in the event based calculator implementation code.

Could you abstract them in an utility function?