augur.curate.format_dates module
Format date fields to ISO 8601 dates (YYYY-MM-DD).
If the provided --expected-date-formats
represent incomplete dates then
the incomplete dates are masked with ‘XX’. For example, providing
%Y
will allow year only dates to be formatted as 2023-XX-XX
.
- augur.curate.format_dates.directive_is_included(potential_directives, date_format)
Checks if any of the directives in potential_directives is included in date_format string.
If an element within potential_directives is a tuple, then all directives within the tuple must be included in date_format.
- Parameters:
- Returns:
Whether the provided date_format includes any of the potential_directives
- Return type:
>>> potential_directives = {('%y', '%b', '%d'), ('%y', '%B', '%d'), ('%y', '%m', '%d'),} >>> directive_is_included(potential_directives, '%G-%V-%A') False >>> directive_is_included(potential_directives, '%y-%m') False >>> directive_is_included(potential_directives, '%%y-%m-%d') False >>> directive_is_included(potential_directives, '%y-%m-%d') True >>> directive_is_included(potential_directives, '%y-%m-%dT%H:%M:%SZ') True
- augur.curate.format_dates.format_date(date_string, expected_formats)
Format date_string to ISO 8601 date (YYYY-MM-DD) by trying to parse it as one of the provided expected_formats.
- Parameters:
- Returns:
Formatted date string or None if the parsing of the date string failed. If date_string is an incomplete date, the date is masked with ‘XX’. Dates without year will be formatted as ‘XXXX-XX-XX’, even if month/day are known. Dates without month will be formatted as ‘YYYY-XX-XX’, even if day is known. Dates without day will be formatted as ‘YYYY-MM-XX’.
- Return type:
str or None
>>> expected_formats = ['%Y', '%Y-%m', '%Y-%m-%d', '%Y-%m-%dT%H:%M:%SZ', '%m-%d'] >>> format_date("", expected_formats) 'XXXX-XX-XX' >>> format_date(" ", expected_formats) 'XXXX-XX-XX' >>> format_date("01-01", expected_formats) 'XXXX-XX-XX' >>> format_date("2020", expected_formats) '2020-XX-XX' >>> format_date("2020-01", expected_formats) '2020-01-XX' >>> format_date("2020-1-15", expected_formats) '2020-01-15' >>> format_date("2020-1-1", expected_formats) '2020-01-01' >>> format_date("2020-01-15", expected_formats) '2020-01-15' >>> format_date("2020-01-15T00:00:00Z", expected_formats) '2020-01-15'
- augur.curate.format_dates.register_parser(parent_subparsers)
- augur.curate.format_dates.run(args, records)