diff --git a/documentation/changelog.rst b/documentation/changelog.rst index ffd451880..64ea3ebb8 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -29,6 +29,7 @@ Bugfixes * Relax constraint validation of `StorageScheduler` to accommodate violations caused by floating point precision [see `PR #731 `_] * Avoid saving any :abbr:`NaN (not a number)` values to the database, when calling ``flexmeasures add report`` [see `PR #735 `_] * Fix browser console error when loading asset or sensor page with only a single data point [see `PR #732 `_] +* Fix defaults for the ``--start-offset`` and ``--end-offset` options to ``flexmeasures add report``, which weren't being interpreted in the local timezone of the reporting sensor [see `PR #744 `_] * Relax constraint for overlaying plot traces for sensors with various resolutions, making it possible to show e.g. two price sensors in one chart, where one of them records hourly prices and the other records quarter-hourly prices [see `PR #743 `_] diff --git a/documentation/cli/change_log.rst b/documentation/cli/change_log.rst index 97fb419ea..2787c7e51 100644 --- a/documentation/cli/change_log.rst +++ b/documentation/cli/change_log.rst @@ -13,6 +13,7 @@ since v0.14.1 | June XX, 2023 ================================= * Avoid saving any :abbr:`NaN (not a number)` values to the database, when calling ``flexmeasures add report``. +* Fix defaults for the ``--start-offset`` and ``--end-offset` options to ``flexmeasures add report``, which weren't being interpreted in the local timezone of the reporting sensor. since v0.14.0 | June 15, 2023 ================================= diff --git a/flexmeasures/cli/data_add.py b/flexmeasures/cli/data_add.py index 9f288cf02..cf31026bf 100755 --- a/flexmeasures/cli/data_add.py +++ b/flexmeasures/cli/data_add.py @@ -5,7 +5,7 @@ from __future__ import annotations from datetime import datetime, timedelta -from typing import Optional, Type +from typing import Type import json from pathlib import Path from io import TextIOBase @@ -66,7 +66,7 @@ ) from flexmeasures.data.services.utils import get_or_create_model from flexmeasures.utils import flexmeasures_inflection -from flexmeasures.utils.time_utils import server_now, get_timezone, apply_offset_chain +from flexmeasures.utils.time_utils import server_now, apply_offset_chain from flexmeasures.utils.unit_utils import convert_units, ur from flexmeasures.data.utils import save_to_db from flexmeasures.data.models.reporting import Reporter @@ -1230,8 +1230,7 @@ def add_schedule_for_storage( "--timezone", "timezone", required=False, - default="UTC", - help="Timezone as string, e.g. 'UTC' or 'Europe/Amsterdam' (defaults to FLEXMEASURES_TIMEZONE config setting)", + help="Timezone as string, e.g. 'UTC' or 'Europe/Amsterdam' (defaults to the timezone of the sensor used to save the report).", ) @click.option( "--dry-run", @@ -1243,26 +1242,26 @@ def add_report( # noqa: C901 reporter_class: str, sensor: Sensor, reporter_config: TextIOBase, - start: Optional[datetime] = None, - end: Optional[datetime] = None, - start_offset: Optional[str] = None, - end_offset: Optional[str] = None, - resolution: Optional[timedelta] = None, - output_file: Optional[Path] = None, + start: datetime | None = None, + end: datetime | None = None, + start_offset: str | None = None, + end_offset: str | None = None, + resolution: timedelta | None = None, + output_file: Path | None = None, dry_run: bool = False, - timezone: str | pytz.BaseTzInfo = get_timezone(), + timezone: str | None = None, ): """ Create a new report using the Reporter class and save the results to the database or export them as CSV or Excel file. """ - # parse timezone into a BaseTzInfo object - if isinstance(timezone, str): + # compute now in the timezone local to the output sensor + if timezone is not None: check_timezone(timezone) - timezone = pytz.timezone(zone=timezone) - - now = timezone.localize(datetime.now()) + now = pytz.timezone( + zone=timezone if timezone is not None else sensor.timezone + ).localize(datetime.now()) # apply offsets, if provided if start_offset is not None: