Closed RoryPTB closed 9 months 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.
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)
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.