Skip to content

Commit

Permalink
add support for yyyy and yymm startdate and enddate precision to the …
Browse files Browse the repository at this point in the history
…framework cli

put in dummy day date precision for startdate and enddate defined as yymm or yyyy to datelabel
remove cropdaterangefunction call from preprocessor execute wrapper as this functionality has been added to checkgroupdaterange
during the catalog query. Retain function in code for reference in case extra start/end time refinement is required
  • Loading branch information
wrongkindofdoctor committed Jul 3, 2024
1 parent 08dceed commit 378d0cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ def check_date_format(date_string: str):
Credit: https://stackoverflow.com/questions/23581128/how-to-format-date-string-via-multiple-formats-in-python
"""

for fmt in ('%Y-%m-%d', '%Y-%m-%d:%H:%M:%S', '%Y%m%d:%H%M%S', '%Y-%m-%d:%H-%M-%S', '%Y%m%d', '%Y%m%d%H%M%S'):
for fmt in ('%Y', '%Y%m', '%Y-%m', '%Y%m%d',
'%Y-%m-%d', '%Y-%m-%d:%H:%M:%S', '%Y%m%d:%H%M%S',
'%Y-%m-%d:%H-%M-%S', '%Y%m%d%H%M%S'):
try:
return datetime.strptime(date_string, fmt)
except ValueError:
pass
raise util.exceptions.MDTFBaseException(
f"Input date string {date_string} does not match accepted formats: YYYY-mm-dd, YYYYmmdd,"
f"Input date string {date_string} does not match accepted formats: YYYY, YYYY-mm-dd, YYYYmmdd,"
f"YYYYmmdd:HHMMSS, YYYY-mm-dd:HH:MM:SS, YYYY-mm-dd:HH-MM-SS"
)

Expand Down
2 changes: 1 addition & 1 deletion src/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def _functions(self):
"""
# normal operation: run all functions
return [
CropDateRangeFunction, AssociatedVariablesFunction,
AssociatedVariablesFunction,
PrecipRateToFluxFunction, ConvertUnitsFunction,
ExtractLevelFunction, RenameVariablesFunction,
]
Expand Down
7 changes: 5 additions & 2 deletions src/util/datelabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,13 @@ def _coerce_to_datetime(dt, is_lower):
)
else:
tmp = Date._coerce_to_self(dt)
date_precision = tmp.precision
if date_precision <= DatePrecision.MONTH:
date_precision = DatePrecision.DAY
if is_lower:
return tmp.lower, tmp.precision
return tmp.lower, date_precision
else:
return tmp.upper, tmp.precision
return tmp.upper, date_precision

@classmethod
def _coerce_to_self(cls, item, precision=None):
Expand Down

0 comments on commit 378d0cf

Please sign in to comment.