Necessary and sufficient conditions for time reversal symmetry in presence of magnetic fields