$\displaystyle
\frac {a} = \frac {-v2-v1}{t2-t1}$
$\displaystyle a=\frac{v_2-v_1}{t_2-t_1}$
We start by multiplying both sides by $\displaystyle t_2-t_1$
$\displaystyle a(t_2-t_1)=v_2-v_1 \iff at_2-at_1=v_2-v_1$ distribute
$\displaystyle -at_1=v_2-v_1-at_2 \iff t_1=\frac{at_2+v_1-v_1}{a}$ isolate $\displaystyle t_1$
$\displaystyle a(t_2 - t_1) = v_2 - v_1$
$\displaystyle at_2 - at_1 = v_2 - v_1$
$\displaystyle -at_1 = v_2 - v_1 - at_2$
$\displaystyle t_1 = -\frac{v_2 - v_1}{a} - t_2$
By the way, your code reads
\frac {a} = \frac {v2-v1}{t2-t1}
What you wanted was
a = \frac {v2-v1}{t2-t1}
-Dan