Please do correct me if I am wrong here - but it is my understanding that the following paragraph holds true:
Let $L$ be the lagrangian of a system with generalised energy $h$ and with $N$ particles, with particle $i$ at position $\bf{r}$$_i$. Then generalised energy of this system is conserved if and only if $\frac{\partial L}{\partial t}=0$ for all time $t$. Also, the generalised energy equals the total energy if $\frac{\partial\bf{r}_i }{\partial t}=0$ for all $i$. And so if both of these conditions are satified then the total energy is conserved.
Assuming I am correct with the above paragraph, let's consider one mass of $m$ on a spring with negligable mass and spring constant $k$. Let's assume that the position of the mass at time $t$ is $x(t)=1-\cos(t)$.
This means that $v(t)=\sin(t)$. And so the Lagrangian of the system is as follows:
$$L=\frac{1}{2}m\sin^2(t)-\frac{1}{2}k(1-\cos(t))^2$$
It then is clear that $\frac{\partial L}{\partial t}\neq0$. And so this would suggest that the generalised energy is not conserved. However this goes against my intuition and doesn't sound right?
I've usually seen Lagrangians written just in terms of the particles' positions. So if we write our Lagrangian in terms of $x$, we get:
$$L=\frac{1}{2}m\dot{x}^2-\frac{1}{2}kx^2$$
Now taking a partial derivative with respect to $t$, if would now follow that $\frac{\partial L}{\partial t}=0$. Ok, so generalised energy is conserved here, but this method neglects the fact that $x$ is a function of time.
This is where my confusion lies - my mathematical intuition tells me $x$ is a function of time and so the generalised energy cannot be conserved. But physically, it should be true that generalised energy is conserved? So my question is whether either of my two approaches above are correct, or whether I have misunderstood something regarding conservation of generalised energy?