  Electric-magnetic duality ($S$-duality) is a well-known property of pure
$u(1)$ gauge theory in 3+1 dimensions. In this paper, we investigate the
compatibility of this duality with time-reversal symmetry. We consider two
theories obtained by coupling a Dirac fermion with an "inverted" sign of the
mass $m$ to a $u(1)$ gauge field. Time-reversal in the two theories is
implemented respectively via the $T$ and $CT$ symmetries of the Dirac fermion.
It was recently conjectured (C. Wang and T. Senthil (arXiv:1505.03520), and M.
Metlitski and A.Vishwanath (arXiv:1505.05142)) that in the $|m| \to \infty$
limit these two theories are $S$-dual to each other. We provide support for
this conjecture by studying partition functions of the two theories on
non-orientable manifolds as a way to probe the realization of time-reversal.
Upon integrating out the Dirac fermion, topological terms in the actions of the
two theories are generated. While on an orientable manifold topological terms
in both theories reduce to a $\theta$-term with $\theta = \pi$, on a
non-orientable manifold they are distinct. We explicitly compute partition
functions of the two theories on the manifold $\mathbb{RP}^4$ and show that
they are equal; this result combined with certain physical arguments is
sufficient to establish the duality. The two theories can be viewed as a gauged
topological insulator in class AII and a gauged topological superconductor in
class AIII, and the bulk duality allows us to derive previously conjectured
non-trivial symmetric gapped surface states of these phases.
