1/4 grid is one beat,
so with
Code:
fullbeats = ({reaper.TimeMap2_timeToBeats( 0, pos )})[4]+10^-14
we convert time in seconds into full beats count (not beats per measure). 10^-14 is the smallest possible increment to say reaper that we always want a next beat. Otherwise if you, say, have edit cursor at exactly 5.0 position, you`ll get 5.0 as next beat (which is the same). So quantizing 5.00000000000001 beat upper give us 6th beat with
Code:
math.ceil(fullbeats)
and
Code:
reaper.TimeMap2_beatsToTime( 0, math.ceil(fullbeats) )
converting full beats into seconds back