Time-Series Forecasting for Out-of-Distribution Generalization Using Invariant Learning