{"id":21106,"library":"datetime-truncate","title":"datetime-truncate","description":"Truncate datetime objects to a specified level of precision (e.g., year, month, day, hour, minute, second). Version 1.1.1 is stable with no active changes; the package is in maintenance mode.","status":"active","version":"1.1.1","language":"python","source_language":"en","source_url":"https://github.com/mediapop/datetime_truncate","tags":["datetime","truncation","python"],"install":[{"cmd":"pip install datetime-truncate","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"datetime_truncate is a separate package, not part of stdlib.","wrong":"from datetime import truncate","symbol":"truncate","correct":"from datetime_truncate import truncate"}],"quickstart":{"code":"from datetime import datetime\nfrom datetime_truncate import truncate\n\ndt = datetime(2025, 4, 15, 10, 30, 45, 123456)\ntruncated = truncate(dt, 'hour')\nprint(truncated)  # 2025-04-15 10:00:00","lang":"python","description":"Truncates to 'year', 'month', 'day', 'hour', 'minute', or 'second'. Returns a new datetime object."},"warnings":[{"fix":"If using 1.0.x, use truncate_to. For 1.1+, use truncate.","message":"The function flips between truncate() and truncate_to(). In version 1.0.0, the function was named truncate_to; in 1.1.0 it was renamed to truncate. Check your version.","severity":"gotcha","affected_versions":">=1.0.0, <1.1.0"},{"fix":"Use 'hour' not 'hours'.","message":"Level parameter uses singular names: 'year', 'month', 'day', 'hour', 'minute', 'second'. Not plural.","severity":"deprecated","affected_versions":"all"},{"fix":"Manually re-attach timezone after truncation: result = truncate(dt, 'day').replace(tzinfo=dt.tzinfo).","message":"Time zones are not preserved; the function returns a naive datetime. If you pass a timezone-aware datetime, the tzinfo is lost.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install latest version: pip install datetime-truncate --upgrade. Then use from datetime_truncate import truncate.","cause":"The function was renamed from truncate_to to truncate in version 1.1.0.","error":"ImportError: cannot import name 'truncate_to' from 'datetime_truncate'"},{"fix":"Import and call truncate() from datetime_truncate, not as a method on a datetime object.","cause":"datetime_truncate does not monkey-patch datetime; it provides a standalone function.","error":"AttributeError: 'datetime.datetime' object has no attribute 'truncate'"},{"fix":"Use 'day' or 'hour' and adjust manually.","cause":"The library does not support truncation to weeks; only year, month, day, hour, minute, second.","error":"ValueError: invalid level: 'weeks'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}