Detect exact intervals

I am using this code to compress the datetime array to 5min intervals:

TFd = TimeFrameCompress( datetime(), 300, compressOpen );

I want to make sure in AFL that the bars have nice and rounded intervals like these:
01:00, 01:05, 01:10, 01:15 etc.

Is the re way to check it? Like somehow take the MOD of the TIME of the bar divided by the 300sec and see if it gives 0 or not.

This could be some example code. I am looking for the code of the ValidTimeframeDate() function.

TF = 300;  // 5min
dts = "2018-04-16 16:25:00";
dt = StrToDateTime(dts);

if (ValidTimeframeDate(TF, dt))
{printf("Yes!\n");    //  Should print Yes!
else
printf("No!\n");
}

dts = "2018-04-16 16:28:00";
dt = StrToDateTime(dts);

if (ValidTimeframeDate(TF, dt))
{printf("Yes!\n");    
else
printf("No!\n");    //  Should print No!
}

@bobptz try this:

function ValidTimeFrameDate( TF, dt )
{
	local HH, MM, SS, seconds;
	
    HH = DateTimeConvert(5, dt);
    MM = DateTimeConvert(4, dt);
    SS = DateTimeConvert(3, dt);
    seconds = (HH * 3600) + (MM * 60) + SS;
    return ( ( seconds % TF ) == 0 );
}

TF = 300;  // 5min
dts = "2018-04-16 16:25:00";
dt = StrToDateTime( dts );

if( ValidTimeFrameDate( TF, dt ) )
    printf( "1 - Yes!\n" );  //  Should print Yes!
else
    printf( "1 - No!\n" );
    
dts = "2018-04-16 16:28:00";
dt = StrToDateTime( dts );

if( ValidTimeframeDate( TF, dt ) )
    printf( "2 - Yes!\n" );
else
    printf( "2 - No!\n" );  //  Should print No!
    

dts = "2018-04-16 12:00:01";
dt = StrToDateTime( dts );

if( ValidTimeframeDate( TF, dt ) )
    printf( "3 - Yes!\n" );
else
    printf( "3 - No!\n" );  //  Should print No!

Or simply

bad5minbar = ( TimeNum() % 500 ) != 0;
1 Like

These are great solutions. Thank you guys.

TimeNum() is briliant, but works for the current bar only. So I will go with the more complicated and more flexible solution from beppe.

1 Like

[quote="bobptz, post:5, topic:5133"]
TimeNum() is briliant, but works for the current bar only. [/quote]

The above statement is incorrect. As fxshrat noted here ( http://forum.amibroker.com/t/timenum/5146/3 ) Timenum() works on the entire arrary.