When defining a spacial area, the prepositions "an", "in", "vor" are so-called two-way prepositions, which take either the accusative or the dative. But in time expressions, they take the dative. The preposition "an" is mostly used for parts of the day (except for "die Nacht") and days of the week.