Periodic functions $f(t)$ (with a time period $T$) can be approximated by a Fourier series, i.e. by summing harmonic oscillations with the discrete frequencies $0, \frac{2\pi}{T}, 2\frac{2\pi}{T}, 3\frac{2\pi}{T}, \ldots$ . $$f(t)=\sum_{n=-\infty}^{+\infty} F_n e^{in\frac{2\pi}{T}t}$$
But, as you already noticed, with a Fourier series you cannot build aperiodic functions (e.g. functions limited to a finite range). For approximating such functions you need a Fourier integral, i.e. summing harmonic oscillations with all frequencies from $0$ to $\infty$. $$f(t)=\int_{-\infty}^{+\infty}F(\omega)e^{i\omega t}\ d\omega$$