The timer is for the collective boost on the building, every investment adds 30 minutes to it (up to 24h) and so long as the building is active the entire city benefits from the collective boost. When it wears off you just stop getting the extra boost, the building won't lose levels or anything.
On a related note, buildings also have instant boosts, which are only for the player who made the investment. Those ones can do things like recover resources instantly, speed up ongoing quests (inn), or speed up the current shop upgrade (town hall).
Click on a building to see its boost information, they can do some pretty neat things