midgard.files.dates

Convenience functions for working with dates

Description:

Formats and converters that can be used for convenience and consistency.

FMT_date (str)

FMT_date = '%Y-%m-%d'

FMT_datetime (str)

FMT_datetime = '%Y-%m-%d %H:%M:%S'

FMT_dt_file (str)

FMT_dt_file = '%Y%m%d-%H%M%S'

date_vars()

date_vars(date:Union[datetime.date, NoneType]) -> Dict[str, str]

Construct a dict of date variables

From a given date, construct a dict containing all relevant date variables. This dict can be used to for instance replace variables in file names.

Examples:

>>> from datetime import date
>>> date_vars(date(2009, 11, 2))  # doctest: +NORMALIZE_WHITESPACE
{'yyyy': '2009', 'ce': '20', 'yy': '09', 'm': '11', 'mm': '11', 'mmm': 'nov', 'MMM': 'NOV', 'd': '2',
 'dd': '02', 'doy': '306', 'dow': '1', 'h': '0', 'hh': '00'}

>>> date_vars(None)
{}

Args:

Returns:

Dictionary with date variables for the given date.