Detect duration of layer I want to get the time / duration of the layer, when I stretch or lengthen the layer to produce an effect, for example I want the opacity of a layer to go to 0% 5 frames before the end of the layer, and if I lengthen or I cut that layer that those 5 frames are the same at the end of the layer, regardless of the length of the layer
This YouTube tutorial explains how to do this:
After Effects Quick Tip - How to Add Auto Opacity To Layers and Footage


Add an expression to the layer's Opacity property by alt-clicking the stopwatch.
Paste this expression into the box:

fadeDuration = .5;
Math.min(linear(time,inPoint,inPoint + fadeDuration, 0, 100), linear(time,outPoint - fadeDuration,outPoint,100,0))

The layer will now fade in for half a second, and then fade out for half a second based on its in and out points.
If want to specify the length in frames instead of seconds, change the first line of the expression to be this:
fadeDuration = thisComp.frameDuration * 5;

Now the layer will fade in and fade out over a period of 5 frames.