First off, "this hour", "today", "this week", etc. all refer to when the submission (link/comment) was created, not when the votes happened. I'll focus on links here, but comments are similarly processed for display on user pages.
Short answer: a bunch of cron jobs pull the relevant time period, sort the links and group them by subreddit, then store cached lists of links for quick perusal.
To elaborate, for each time period, there's a different cron job. The "top this hour" job runs much more frequently than the "top this year" job for example. The first thing each job does is pull down a list of all links from the database that were created in the time period of interest. This gets dumped out to a text file where a primitive map-reduce system processes the data. The links are grouped and sorted. The final list of results is then put into Cassandra as a simple list of link IDs which are very quick to look up in-request.
Source: https://github.com/reddit/reddit/blob/master/scripts/compute_time_listings
FWIW, individual votes do have timestamps attached to them, but they're not directly used for tracking Top.