01 - Preheat the oven to 350°F. Generously butter a 2-quart gratin dish to prevent sticking.
02 - In a saucepan, combine heavy cream, whole milk, minced garlic, ground nutmeg, sea salt, black pepper, and thyme leaves. Warm gently over medium heat until just steaming without boiling. Remove from heat.
03 - Arrange half of the sliced potatoes in overlapping layers in the prepared dish. Add half the sliced onions if using, followed by half the Gruyère and Parmesan cheeses.
04 - Pour half of the warm cream mixture evenly over the layered ingredients.
05 - Repeat layers with remaining potatoes, onions, Gruyère, and Parmesan. Press down gently to level the layers.
06 - Dot the surface with butter and sprinkle additional Gruyère and a few thyme leaves. Cover tightly with aluminum foil.
07 - Bake covered for 40 minutes. Remove foil and continue baking an additional 20 minutes until the top is golden brown and bubbling.
08 - Allow the gratin to rest for 10 minutes before serving. Garnish with fresh thyme leaves.