augur.curate.format_dates moduleο
Format date fields to Augur-compatible formats.
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 an Augur-compatible format.
>>> format_date("2020-01-15", BUILTIN_DATE_FORMATS) '2020-01-15' >>> format_date("[2001 TO 2002]", BUILTIN_DATE_FORMATS) '2001-01-01/2002-12-31'
- augur.curate.format_dates.format_to_iso_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:
str or None -- 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β.
>>> format_to_iso_date(ββ, BUILTIN_DATE_FORMATS)
βXXXX-XX-XXβ
>>> format_to_iso_date(β β, BUILTIN_DATE_FORMATS)
βXXXX-XX-XXβ
>>> format_to_iso_date(β01-01β, [β%m-%dβ])
βXXXX-XX-XXβ
>>> format_to_iso_date(β2020β, [β%Yβ])
β2020-XX-XXβ
>>> format_to_iso_date(β2020-01β, [β%Y-%mβ])
β2020-01-XXβ
>>> format_to_iso_date(β2020-1-15β, [β%Y-%m-%dβ])
β2020-01-15β
>>> format_to_iso_date(β2020-1-1β, [β%Y-%m-%dβ])
β2020-01-01β
>>> format_to_iso_date(β2020-01-15β, BUILTIN_DATE_FORMATS)
β2020-01-15β
>>> format_to_iso_date(β2020-01-15T00 (00:00Zβ, [β%Y-%m-%dT%H:%M:%SZβ]))
β2020-01-15β
>>> format_to_iso_date(β[2001 TO 2002]β, BUILTIN_DATE_FORMATS) is None
True
- augur.curate.format_dates.format_to_iso_interval(date_string)ο
Format date_string to an ISO 8601 interval, compatible with RE_DATE_RANGE in augur.dates.
>>> format_to_iso_interval("[2001 TO 2002]") '2001-01-01/2002-12-31' >>> format_to_iso_interval("2001-01-01/2002-12-31") '2001-01-01/2002-12-31'
- augur.curate.format_dates.register_parser(parent_subparsers)ο
- augur.curate.format_dates.run(args, records)ο