avatar Bite 141. Primitive date format inferrer

Complete the get_dates method given the following:

  • a listing of date strings in unknown date format and
  • an enum class which contains allowed/supported date formats

Although the following assignment text is wordy, once you will see test cases the task definition will become clearer.

The get_dates method will return a list of date strings in the format yyyy-mm-dd.

The date format of input date strings will be inferred based on the most prevalent allowed date format of items in the list. Allowed/supported date formats are defined in an enum class.

The most prevalent allowed date format of items must represent a single most frequent date format. If there are two most frequent formats with the same frequency raise a (custom) InfDateFmtError exception.

Items in an input list can be in any format no matter whether or not this format is listed in the DateFormat enum class. Items can be even values which cannot represent a date at all. Those items are nonparsable. If the frequency of nonparsable elements is higher than the frequency of other allowed date formats (counted individually for each format) raise a custom InfDateFmtError exception.

Once you have the most prevalent date format, parse dates in an input list and return them as a list of strings in the format yyyy-mm-dd.

Dates which are not parsable replace with the string Invalid.

Important note: the list of allowed/supported date formats is supposed to be stored in the DateFormat enum class only. The DateFormat enum class is subject of change and this change is not under your control.

As a hint, you are provided with a helper method _maybe_DFs which shows how to work with the DateFormat enum class.

This assignment introduces a very simple date format inferrer. For more serious work you can check out: dateparser or dateinfer

Login and get coding
go back Intermediate level
Bitecoin 3X

118 out of 120 users completed this Bite.
Will you be the 119th person to crack this Bite?
Resolution time: ~76 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 6.67 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help