Pulse extender

Hello,
I’m trying to make pulse extender, that has following conditios, but there appears to be some accuracy issues or something;
if input pulse duration is shorter than threshold, output duration is threshold.
if input pulse duration is longer than threshold, output duration is input duration (whenever input falls)
so, essentially threshold acts as minimum output pulse width, and input as maximum
so examples;
input is 10ms, threshold is 50ms, output is then 50ms.
input is 100 ms, threshold is 50ms, output is then 100ms.

So far, this ise the code I’ve gotten together. I use afunction generator to create input pulse
I don’t think that this would be wise to make with discreet components, since I plan to make this adjustable.Time range would be from what, hmm…second to hour, I believe that is doable with arduino clock.

Oh, and I use arduino UNO.
That’s all I can think of! It’s been while since I asked anything here, but tried to play by book here.

#include <digitalWriteFast.h>

byte ledPin = 13;
byte detectPin = 2;
boolean detect = false;
unsigned long previousMillis = 0;
unsigned long minPulseOut = 20; //threshold time
boolean timeOut;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(detectPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(detectPin), Pulse, RISING);
}

void loop()
{




  if (detect == true)
  {
    digitalWriteFast(ledPin, HIGH); //output on right away.
    unsigned long currentMillis = millis(); //time when detection happened

    if (currentMillis - previousMillis >= minPulseOut &&  digitalReadFast(detectPin) == LOW) //if time is up and signal is no more either
    {

      previousMillis = currentMillis;
      digitalWriteFast(ledPin, LOW);
      detect = false; //ok, time for another detection
    }

    if (currentMillis - previousMillis >= minPulseOut && digitalReadFast(detectPin) == HIGH) //if time is up, but signal is still up
    {
      timeOut = true;
      digitalWriteFast(ledPin, HIGH);

    }
  }

  if (timeOut == true && digitalReadFast(detectPin) == LOW) //if timeout has occured and signal finlly goes down
  {
    digitalWriteFast(ledPin, LOW);
    timeOut = false;
  }
}


void Pulse() //ISR only sets this boolean
{
  detect = true;
}

Aside from all the useless white space, is there a problem with the code?

Seems I joyed too early, it doesn't work at all it seems. The code I posted, but with 1000ms threshold, gives this output. Yellow is input, blue is output. SeemsI didn't save tuly working one, which is unlikely, since I save very often.
https://imgur.com/MVGAl5D
https://imgur.com/Ux0SA2l

Back to drawing board!