وَكُلُّهَا مَنْصُوبٌ بِتَقْدِيرِ «فِي»، تَقُولُ: «صُمْتُ دَهْرًا، وَسَافَرْتُ شَهْرًا» أَيْ: فِي دَهْرٍ وَفِي شَهْرٍ.
Translation: Both time classes can be accusative adverbials, understood with an implicit “in/during”; e.g., I fasted for a long period and travelled for a month.
An understood fī explains the temporal relation; it is not an actually spoken preposition. If fī is pronounced, its noun is genitive instead.