Better logic calculate time

Maybe you can calculate it with HomeyScript, like in:

Or the app: Flow Utilities?