Preheat the oven to 375°F (190°C).
In a medium saucepan, heat the heavy cream over medium heat until it's warm but not boiling. Add the minced garlic and fresh thyme leaves, and let the flavors infuse into the cream for about 5 minutes. Remove from heat and set aside.
Grease a baking dish with butter. Layer the sliced potatoes in the dish, slightly overlapping them to create even layers.
Season each layer of potatoes with a pinch of salt and pepper.
Sprinkle a generous layer of shredded Gruyère cheese over the potatoes.
Pour a portion of the infused cream over the cheese and potatoes, ensuring that the cream seeps through the layers.
Repeat the process with another layer of potatoes, salt, pepper, Gruyère cheese, and cream until you've used up all the ingredients. Make sure the top layer is covered with cream and cheese.
Sprinkle the shredded Parmesan cheese evenly over the top layer.
Cover the baking dish with aluminum foil and place it in the preheated oven.
Bake for about 45 minutes, then remove the foil to allow the top to brown and the cheese to become bubbly and golden. This usually takes an additional 15-20 minutes.
Once the gratin is cooked through and the top is beautifully browned, remove it from the oven.
Let the gratin rest for a few minutes before serving to allow the flavors to meld together.
Serve the cheesy potato gratin warm and enjoy!