Check that the joystick is being pressed for a few seconds

I have a joystick that plays two animations, one when pressed/dragged and one at the time of releasing it, does its job, but halfway, it only looks good if the joystick is pressed for several seconds, however if one quickly presses the joystick the animation when you stop pressing the joystick plays, generating an animation error.
The animation plays earlier than it should.

So I would like to make the joystick able to check that it is being pressed for a few seconds to authorize the animation to run. Is there any way to do this? Thank you in advance.

You could start a timer in the Update, for example (pseudocode ahead):

float time = 0f;

void Update()
{
     if (JoystickIsPressed)
     {
          CheckJoystickPress(3);
     }

     if (JoystickIsLetGo)
     {           
          if (time >= maxTime)
          {
                // Joystick was held for more than 3 seconds
                PlayAnimation();
                time = 0;
          }
     }
}

void CheckJoystickPress(float maxTime)
{
     if (time < maxTime)
     {
            time += Time.deltaTime;
     }
}