Aside from minutesWithin(), you can also simply get the current time inside the tick() function, and subtract the time from one bar before.

For obvious reasons, no matter how small your bar period, minutesWithin() can, and often will, return ranges of up to about 3000 minutes. BarPeriod=2 gives only the MINIMUM length of a bar.