@@ -73,9 +73,9 @@ def get_era5(latitude, longitude, start, end, variables, api_key,
7373 longitude: float
7474 In decimal degrees, east is positive (ISO 19115).
7575 start : datetime like or str
76- First day of the requested period.
76+ First day of the requested period. Assumed to be UTC if not localized.
7777 end : datetime like or str
78- Last day of the requested period.
78+ Last day of the requested period. Assumed to be UTC if not localized.
7979 variables : list of str
8080 List of variable names to retrieve, for example ``['ghi',
8181 'temp_air']``. See [1]_ for additional options.
@@ -109,8 +109,15 @@ def get_era5(latitude, longitude, start, end, variables, api_key,
109109 .. [2] https://cds.climate.copernicus.eu/datasets/reanalysis-era5-single-levels-timeseries?tab=overview
110110 .. [3] https://confluence.ecmwf.int/pages/viewpage.action?pageId=505390919
111111 """ # noqa: E501
112- start = pd .to_datetime (start ).strftime ("%Y-%m-%d" )
113- end = pd .to_datetime (end ).strftime ("%Y-%m-%d" )
112+
113+ def _to_utc_dt_notz (dt ):
114+ dt = pd .to_datetime (dt )
115+ if dt .tzinfo is not None :
116+ dt = dt .tz_convert ("UTC" )
117+ return dt
118+
119+ start = _to_utc_dt_notz (start ).strftime ("%Y-%m-%d" )
120+ end = _to_utc_dt_notz (end ).strftime ("%Y-%m-%d" )
114121
115122 headers = {'PRIVATE-TOKEN' : api_key }
116123
0 commit comments