Find mistake in Fourier series calculation. 
The function $f$ is $3$-periodic and $$f(t)=\left\{
                 \begin{array}{ll}
                   t,\quad &0\leq t\leq1\\
                   1,\quad &1<t<2\\
                   3-t,\quad &2\leq t \leq 3
                 \end{array}
               \right. $$


Expand $f$ as a (real) Fourier series.

Attempt: I simply use the formulae for $a_0,a_n$ and $b_n$. The value of $L$ is $2L=3\Leftrightarrow L=3/2.$ this gives
$$a_0=\frac1{2L}\int\limits_{-L}^Lf(t)\,\mathrm dt=\frac13\cdot2=\frac23,$$
which also is easy to see by drawing $f(t)$. Now
\begin{align}
a_n &=\frac23\left[\,\int\limits_{-3/2}^{-1}\cos\left(\frac{2\pi nt}3\right)\,\mathrm dt-\int\limits_{-1}^0t\cos\left(\frac{2\pi nt}3\right)\,\mathrm dt+\int\limits_0^1t\cos\left(\frac{2\pi nt}3\right)\,\mathrm dt+\int\limits_1^{3/2}\cos\left(\frac{2\pi nt}3\right)\,\mathrm dt\,\right]\\
&=\frac{\sin(\pi n)-\sin\left(\frac{2\pi n}{3}\right)}{\pi n},
\end{align}
since the two middle integrals cancel and the two outer are the same. For $b_n$ I have, with identical integrals as above but replacing $\cos$ by $\sin$, that $b_n=0$. This means that
\begin{align}
f(t)&=\frac{2}{3}-\sum_{n=1}^{\infty}\frac{\sin(\pi n)-\sin\left(\frac{2\pi n}{3}\right)}{\pi n}\cos\left(\frac{2\pi nt}{3}\right)\\
&=\frac{2}{3}-\frac{2}{\pi}\sum_{n=1}^{\infty}\frac{\sin{\left(\frac{2\pi n}{3}\right)}}{n}\cos\left(\frac{2\pi nt}{3}\right),
\end{align}
since $\sin(\pi n)=0 \ \forall \ n\in\mathbb{Z}.$ However the book wants the answer to be
$$f(t)=\frac{2}{3}-\frac{3}{\pi^2}\sum_{n=1}^{\infty}\frac{1-\cos\left(\frac{2\pi n}{3}\right)}{n^2}\cos\left(\frac{2\pi nt}{3}\right).$$
Can someone help me find the mistake?


since the two middle integrals cancel...

They don't. Our $f(t)=\begin{cases}1&-\frac32 \le t\le -1\\-t&-1\le t\le 0\\t&0\le t\le 1\\1&1\le t\le \frac32\end{cases}$ is even. Integrate it against an odd function like $\sin\left(\frac{2\pi nt}{3}\right)$ and we'll get zero by odd symmetry. Integrate it against something even like $\cos\left(\frac{2\pi nt}{3}\right)$, and the parts for negative $t$ will mirror the parts for positive $t$ and reinforce each other, doubling the total value. By even symmetry,
\begin{align*}a_n &= \frac23\int_{-\frac32}^{\frac32}f(t)\cos\left(\frac{2\pi nt}{3}\right)\,dt = \frac43\int_{0}^{\frac32}f(t)\cos\left(\frac{2\pi nt}{3}\right)\,dt\\
a_n &= \frac43\int_0^1 t\cos\left(\frac{2\pi nt}{3}\right)\,dt+\frac43\int_1^{\frac32}\cos\left(\frac{2\pi nt}{3}\right)\,dt\\
a_n &= \frac43\left[\frac{3t}{2\pi n}\sin\left(\frac{2\pi nt}{3}\right)+\frac{9}{4\pi^2 n^2}\cos\left(\frac{2\pi nt}{3}\right)\right]_0^1 +\frac43\left[\frac{3}{2\pi n}\sin\left(\frac{2\pi nt}{3}\right)\right]_1^{\frac32}\\
a_n &= \frac2{\pi n}\sin\left(\frac{2\pi n}{3}\right) +\frac{3}{\pi^2 n^2}\left(1-\cos\left(\frac{2\pi n}{3}\right)\right) + \frac2{\pi n}\left(\sin\pi n - \sin\left(\frac{2\pi n}{3}\right)\right)\\
a_n &= \frac{3}{\pi^2 n^2}+\frac2{\pi n}(\sin(\pi n))-\frac{3}{\pi n^2}\cos\left(\frac{2\pi n}{3}\right)\\
a_n &= \begin{cases}\frac23& n=0\\ 0& 3\mid n,n>0\\ \frac{9}{2\pi^2 n^2}& 3\nmid n\end{cases}\end{align*}
In that last step, we use that $\sin(\pi n) = 0$ and $\cos\left(\frac{2\pi n}{3}\right)$ has a cycle of values $1,-\frac12,-\frac12$; subtract that from $1$ and it becomes $0,\frac32,\frac32$. Also, we incorporate the previously calculated (by a different method) $a_0$. The book's version of the answer applies the $\sin(\pi n)=0$ fact, but doesn't do anything with the $\cos\left(\frac{2\pi n}{3}\right)$ term.
So there it is. Incorporate the middle part of the integral as it should be for this even function, and we get the right answer.
