You can temporarily gain the Well Rested perk, adding +10% experience, by sleeping in an owned bed. You can instead temporarily gain the Lover's Embrace perk, adding +15% experience, by sleeping in any bed with a romantic companion nearby.
How long do these bonuses last?
I've heard 12 hours, which is listed on both those Nukapedia pages, but it doesn't always seem to be true. Checking the in-game clock, I've fast traveled to somewhere less than 7 hours away and lost the bonus.
What actions will cause them to end prematurely?
I know that sleeping in any bed will you cause you to lose Well Rested. Will anything else cause these perks to end early?