24hr clock with sun and moon info, but moon is being wonky one or so days per month

I am not a programmer. This issue happen when moonrise crosses midnight. (Disappears)

Using a circle progress bar with these globals:
Set
$if(tf(ai(moonset) - dp(0h0m),M)>1439,tf(ai(moonset) - dp(0h0ma1d),M),tf(ai(moonset) - dp(0h0m),M))$
Rise
$if(tf(ai(moonrise) - dp(0h0m),M)>1439,tf(ai(moonrise) - dp(0h0ma1d),M),tf(ai(moonrise) - dp(0h0m),M))$

The level min 0 max 1439, 360 sections
$if(gv(set)>gv(rise),
tf(ai(moonset)-ai(moonrise),M),tf(ai(moonset, a1d)-ai(moonrise),M))$

Rotation on gv(rise)

I want it to show current moon while it is up, then change to next while it is down…