Time-dependent lunar electric and magnetic fields induced by a spatially varying interplanetary magnetic field