The halving is set to be every 210.000th block. On average the block time (time to create a new block) is 10 minutes. But as the total hash rate goes up and down, the block time can vary.
At the time i wrote this post, there had been 10 blocks the last hour. With that speed the halving date would come earlier.
Smart AF, satoshi fixed this with a difficulty adjustment.
So every 2016th block, the difficulty of creating a block adjusts based on the hashrate.