Integrate a periodic absolute value function \begin{equation}
\int_{0}^t \left|\cos(t)\right|dt = \sin\left(t-\pi\left\lfloor{\frac{t}{\pi}+\frac{1}{2}}\right\rfloor\right)+2\left\lfloor{\frac{t}{\pi}+\frac{1}{2}}\right\rfloor
\end{equation}
I got the above integral from https://www.physicsforums.com/threads/closed-form-integral-of-abs-cos-x.761872/. It seems to hold and the way I approached it was to see that the integrand was periodic and $\int_{\frac{\pi}{2}}^\frac{3\pi}{2} -\cos(t)dt=\int_{\frac{3\pi}{2}}^{\frac{5\pi}{2}} \cos(t)dt=\ldots=2$.
I need to evaluate a similar integral.
\begin{equation}
\int_{0}^t \sin\left(\frac{1}{2}(s-t)\right)\left|\sin\left(\frac{1}{2}s\right)\right|ds
\end{equation}
Here too the integrand is periodic but I am unable to get the closed form. Can someone help me out?

We can use the Fourier series of the square wave. We have:
$$\operatorname{sign}\left(\sin\frac{s}{2}\right)=\frac{4}{\pi}\sum_{k=0}^{+\infty}\frac{1}{2k+1}\sin\frac{(2k+1)s}{2},$$
and since:
$$\frac{1}{2k+1}\int_{0}^{t}\sin\frac{t-s}{2}\sin\frac{s}{2}\sin\frac{(2k+1)s}{2}\,ds=\\ = \frac{4\cos(t/2)}{(2k-1)(2k+1)^2(2k+3)}-\frac{\cos(kt)}{(2k-1)(2k+1)^2}+\frac{\cos((k+1)t)}{(2k+1)^2(2k+3)}$$
we have:
$$\color{red}{\int_{0}^{t}\sin\frac{t-s}{2}\left|\sin\frac{s}{2}\right|\,dt} =\\= -\frac{\pi}{2}\cos\frac{t}{2}-\frac{4}{\pi}\sum_{k=0}^{+\infty}\left(\frac{\cos(kt)}{(2k-1)(2k+1)^2}-\frac{\cos((k+1)t)}{(2k+1)^2(2k+3)}\right)=\\=-\frac{\pi}{2}\cos\frac{t}{2}-\frac{4}{\pi}\left(-1-2\sum_{k=1}^{+\infty}\frac{\cos(kt)}{(2k-1)^2(2k+1)^2}\right)=\\=\color{red}{\frac{4}{\pi}-\frac{\pi}{2}\cos\frac{t}{2}+\frac{8}{\pi}\sum_{k=1}^{+\infty}\frac{\cos(kt)}{(2k-1)^2(2k+1)^2}}.$$
The last sum gives a $2\pi$-periodic function whose absolute value is always $\leq\frac{\pi^2-8}{2\pi}=0.297556782\ldots<0.3.$ It is also interesting to notice that the integral, as a function of $t$, is pretty well gaussian-shaped on the interval $[0,4\pi]$:

