  Violations of $ CPT$ symmetry and Lorentz invariance are searched for by
studying interference effects in $ B^0$ mixing and in $ B^0_s$ mixing. Samples
of $ B^0\to J/\psi K^0_{\mathrm{S}}$ and $ B^0_s\to J/\psi K^+ K^-$ decays are
recorded by the LHCb detector in proton--proton collisions at centre-of-mass
energies of 7 and 8 TeV, corresponding to an integrated luminosity of 3
fb$^{-1}$. No periodic variations of the particle-antiparticle mass differences
are found, consistent with Lorentz invariance and $ CPT$ symmetry. Results are
expressed in terms of the Standard Model Extension parameter $\Delta a_{\mu}$
with precisions of $ \mathcal{O}(10^{-15})$ and $ \mathcal{O}(10^{-14})$ GeV
for the $ B^0$ and $ B^0_s$ systems, respectively. With no assumption on
Lorentz (non-)invariance, the $ CPT$-violating parameter $z$ in the $ B^0_s$
system is measured for the first time and found to be $ \mathcal{R}e(z) =
-0.022 \pm 0.033 \pm 0.005$ and $ \mathcal{I}m(z) = 0.004 \pm 0.011\pm 0.002$,
where the first uncertainties are statistical and the second systematic.
