diff --git a/projects/common/src/fm/services/weather.service.ts b/projects/common/src/fm/services/weather.service.ts index f2b0511..bd2ddfd 100644 --- a/projects/common/src/fm/services/weather.service.ts +++ b/projects/common/src/fm/services/weather.service.ts @@ -49,6 +49,22 @@ export class WeatherService { return this.getWeatherRange(centroid, startDateString, endDateString); } + public getDailyHistoricalObservations(centroid: number[], startDate: string, endDate: string): Observable { + const endpoint = this.appConfig.getConfig('weatherApiEndPoint'); + const apiKey = this.appConfig.getConfig('weatherApiKey'); + + // weather does not support UTC format, also remove Z + const sd = encodeURIComponent(startDate); + + const edHistoricalDate = new Date(); + edHistoricalDate.setHours(edHistoricalDate.getHours(), 0, 0, 0); + const edHistorical = moment(edHistoricalDate).local().format('YYYY-MM-DD[T]HH:mm:ss'); + + const historical = `${endpoint}${this.apiObservation}/?c=${centroid[0]},${centroid[1]}&sd=${sd}&ed=${edHistorical}&t=cleanedobservation&interval=daily&key=${apiKey}`; + + return this.httpClient.get(historical); + } + public getWeatherRange(centroid: number[], startDate: string, endDate: string): Observable { const endpoint = this.appConfig.getConfig('weatherApiEndPoint'); const apiKey = this.appConfig.getConfig('weatherApiKey');