wmo-im / synop2bufr

Python package to transform SYNOP data into the WMO BUFR format.
https://synop2bufr.readthedocs.io
Apache License 2.0
6 stars 2 forks source link

Default year/month in the CLI not corresponding to day of month in the data #23

Closed RoryPTB closed 9 months ago

RoryPTB commented 1 year ago

When using the default year and month in the CLI, there is a possibility that it is not compatible with the day of the month found in the data. For example, if the day of the month is 31, then using the default year/month right now gives a date of 31st June 2023, which causes an error. This can either be resolved by doing a validation of the proposed date before encoding, or by scrapping the default year/month altogether.

RoryPTB commented 1 year ago

Suggested fix: check the current day of the month, and if that day is before the day specified in the synop report, then default the month to the previous month.

tomkralidis commented 1 year ago

Option (assumes year/month passed via CLI or API):

from datetime import datetime

year = 2023
month = 6
day = 31

try:
    ymd = datetime(year, month, day)
except ValueError as err:
    msg = f'Invalid date: {err}'
    LOGGER.error(msg)
    raise RuntimeError(msg)

Related: https://github.com/wmo-im/synop2bufr/pull/27 (forces year/month from CLI)

david-i-berry commented 1 year ago

Closed by https://github.com/wmo-im/synop2bufr/pull/27