{"id":9643,"library":"datetime-quarter","title":"datetime-quarter library","description":"datetime-quarter is a simple and lightweight Python library that adds quarter-level support to standard `datetime` objects. It provides a `QuarterDateTime` class, allowing creation of objects representing a specific year and quarter, and methods to easily derive the start and end `datetime` for that quarter. The current version is 1.0.3, and it appears to have a stable but infrequent release cadence.","status":"active","version":"1.0.3","language":"en","source_language":"en","source_url":"https://github.com/BetaS/datetime-quarter","tags":["datetime","quarter","date","time"],"install":[{"cmd":"pip install datetime-quarter","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"QuarterDateTime","correct":"from datetime_quarter import QuarterDateTime"}],"quickstart":{"code":"from datetime import datetime\nfrom datetime_quarter import QuarterDateTime\n\n# Create a QuarterDateTime object from a standard datetime\ndt_obj = datetime(2023, 7, 15)\nq_dt_from_dt = QuarterDateTime.from_datetime(dt_obj)\nprint(f\"From datetime {dt_obj}: Year={q_dt_from_dt.year}, Quarter={q_dt_from_dt.quarter}\")\nprint(f\"Start of quarter: {q_dt_from_dt.start_of_quarter}\")\nprint(f\"End of quarter: {q_dt_from_dt.end_of_quarter}\")\n\n# Create a QuarterDateTime object directly with year and quarter\nq_dt_direct = QuarterDateTime(2024, 1)\nprint(f\"Directly created: {q_dt_direct}\")\nprint(f\"Start of quarter: {q_dt_direct.start_of_quarter}\")\n\n# Perform comparisons\nprint(f\"Is 2023Q1 before 2023Q2? {QuarterDateTime(2023, 1) < QuarterDateTime(2023, 2)}\")","lang":"python","description":"Demonstrates creating `QuarterDateTime` objects from existing `datetime` objects or directly, and accessing its properties like year, quarter, and the start/end `datetime` of the quarter. Also shows basic comparison."},"warnings":[{"fix":"Use `.start_of_quarter` or `.end_of_quarter` methods to get a standard `datetime` object if you need fine-grained date/time manipulation or formatting.","message":"The `QuarterDateTime` object does not inherit directly from `datetime` and thus lacks many standard `datetime` attributes and methods (e.g., `day`, `hour`, `strftime`). It represents a quarter, not a specific point in time.","severity":"gotcha","affected_versions":"All versions"},{"fix":"This is by design. Ensure your logic correctly accounts for quarter definition based on month boundaries.","message":"When creating `QuarterDateTime` from a `datetime` object using `QuarterDateTime.from_datetime()`, the quarter is determined solely by the month of the input `datetime`. The day or time components are ignored.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure the library is installed with `pip install datetime-quarter` and verify the import path is `from datetime_quarter import QuarterDateTime`.","cause":"The `datetime-quarter` library is either not installed or there is a typo in the import statement.","error":"ImportError: cannot import name 'QuarterDateTime' from 'datetime_quarter'"},{"fix":"If you need a `datetime` object with specific date/time components, convert the `QuarterDateTime` to a standard `datetime` using its `.start_of_quarter` or `.end_of_quarter` properties.","cause":"`QuarterDateTime` objects represent an entire quarter, not a specific date and time. They do not possess attributes for day, hour, minute, etc., which are specific to `datetime` objects.","error":"AttributeError: 'QuarterDateTime' object has no attribute 'day' (or 'hour', 'minute', etc.)"}]}