undated.fmts

The fmts (formattings) module comes into play when the date data format is unknown. It has two key class objects. The Deriver class derives the date format from a list of dates, returning an UndatedFormat class object, which contains the information required by the as_parts function to extract the date elements.

class undated.fmts.Deriver

Facilitates the searching of dates to derive the format

search(dates: Union[list, str, tuple]) Optional[UndatedFormat]

Search through a list of dates to derive the date format

Caution

All of the dates in the list passed to the search method are expected to be in the same format.

Parameters

dates – list or tuple of dates to search. Or str for one date

Returns

the derived UndatedFormat object

set_parameters(params: dict)

Sets the optional parameters for the search

Parameters

params – see tutorial for possible parameters

class undated.fmts.UndatedFormat(split: list[int, int, int], keys: list[str, str, str], steps: dict, valid: bool)

Properties for the format. Created by the Deriver class or convert_format function

undated.fmts.as_parts(sdate: Union[int, str], fmt: Union[str, UndatedFormat], yy_pivot: Optional[int] = None) Optional[tuple]

Converts the sdate to year, month, day, based on the format

Parameters
  • sdate – The date as a str or int

  • fmt – The date format, as either a basic format as a string, or a derived format

  • yy_pivot – The pivot year for two digit years. Use with string based formats

undated.fmts.convert_format(fmt: str, yy_pivot: Optional[int] = None) UndatedFormat

Converts the basic string format into an UndatedFormat object. Recommended when looping, to prevent repeated format conversion.

Parameters
  • fmt – The string format. See the tutorial for valid values.

  • yy_pivot – The pivot year for two digit years. Use only with string based formats.