{"id":4692,"library":"prefixdate","title":"Prefixdate","description":"Prefixdate (version 0.5.0) is a Python library for parsing and processing date strings with varied levels of precision, such as '2001', '2001-4', or '2001-04-02'. It converts these partial dates into a structured format, enabling validation and re-formatting (e.g., normalizing '2001-4' to '2001-04'). The library is designed for handling ambiguous date prefixes and does not aim for full compliance with ISO 8601 or RFC 3339 standards, specifically excluding date ranges or calendar-week/day-of-year notations. It requires Python >=3.9. The latest version was released on August 4, 2025.","status":"active","version":"0.5.0","language":"en","source_language":"en","source_url":"http://github.com/pudo/prefixdate","tags":["date parsing","partial dates","date precision","datetime"],"install":[{"cmd":"pip install prefixdate","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"parse","correct":"from prefixdate import parse"},{"symbol":"normalize_date","correct":"from prefixdate import normalize_date"},{"symbol":"Precision","correct":"from prefixdate import Precision"},{"symbol":"parse_parts","correct":"from prefixdate import parse_parts"}],"quickstart":{"code":"from prefixdate import parse, normalize_date, Precision, parse_parts\nfrom datetime import datetime\n\n# Parse returns a `DatePrefix` object:\ndate_obj_month = parse('2001-3')\nassert date_obj_month.text == '2001-03'\nassert date_obj_month.precision == Precision.MONTH\n\ndate_obj_year = parse(2001)\nassert date_obj_year.text == '2001'\nassert date_obj_year.precision == Precision.YEAR\n\n# Handle invalid input which results in an empty DatePrefix\ndate_obj_invalid = parse('Not-a-date')\nassert date_obj_invalid.text is None\nassert date_obj_invalid.precision == Precision.EMPTY\n\n# Normalize to a standard string:\nassert normalize_date('2001-1') == '2001-01'\nassert normalize_date('2001-00-00') == '2001'\n\n# Normalize a datetime object with specific precision:\nnow_utc_iso = datetime.utcnow().isoformat()\nminute_precision_date = normalize_date(now_utc_iso, precision=Precision.MINUTE)\n# Example output for minute_precision_date: 'YYYY-MM-DDTHH:MM'\n\n# Using parse_parts for structured input:\ndate_from_parts = parse_parts(2001, '3', None)\nassert date_from_parts.precision == Precision.MONTH\nassert date_from_parts.text == '2001-03'\n","lang":"python","description":"This quickstart demonstrates how to parse various date strings and integers into `DatePrefix` objects, normalize them to standard formats, and use `parse_parts` for structured date input. It also shows how to handle invalid date inputs and specify output precision."},"warnings":[{"fix":"Manually handle timezone conversion before or after using `prefixdate` if aware datetimes are critical.","message":"All `datetime` objects are converted to UTC and made naive (timezone information is stripped). Be aware of potential timezone issues if your application requires preserving original timezone data.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For full ISO 8601/RFC 3339 compliance, consider alternative libraries or custom parsing solutions.","message":"The library explicitly does not support the full complexities of ISO 8601 and RFC 3339 standards, including date ranges and calendar-week/day-of-year notations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check the `text` and `precision` attributes of the returned `DatePrefix` object for `None` or `Precision.EMPTY` to handle invalid inputs gracefully.","message":"Invalid date strings (e.g., 'Boo!') or `None` passed to `parse()` will result in a `DatePrefix` object with `text` as `None` and `precision` as `Precision.EMPTY`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Trim milliseconds from input strings if they are not relevant, or use other parsing methods for inputs requiring millisecond precision.","message":"The library does not currently process milliseconds in date strings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement separate validation logic using Python's `datetime` module or other date validation libraries if strict calendrical validity is required.","message":"The library does not validate for calendrically invalid dates (e.g., 'February 31st'). It focuses on string format parsing rather than date validity checks.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}