{"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,"search_vec":"'1.1.1':21 'activ':26 'chang':27 'datetim':2,5,34 'datetime-trunc':1 'day':16 'e.g':13 'hour':17 'level':10 'mainten':32 'minut':18 'mode':33 'month':15 'object':6 'packag':29 'precis':12 'python':36 'second':19 'specifi':9 'stabl':23 'truncat':3,4,35 'version':20 'year':14","created_at":"2026-04-27T16:58:07.724188+00:00","updated_at":"2026-04-27T16:58:07.724188+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.1.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/mediapop/datetime_truncate","docs":null,"changelog":null,"pypi":"https://pypi.org/project/datetime-truncate/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}