{"id":7426,"library":"moment","title":"Moment","description":"Moment is a Python library designed for simplifying date and time manipulation, drawing inspiration from Moment.js and Kenneth Reitz's Requests library. It provides an intuitive API for parsing, formatting, and performing calculations with dates and times. The library is currently at version 0.12.1, but its GitHub repository shows no activity since 2015, and it is explicitly labeled as deprecated by recent analyses, with recommendations to use more actively maintained alternatives like `arrow` or `pendulum`.","status":"deprecated","version":"0.12.1","language":"en","source_language":"en","source_url":"http://github.com/zachwill/moment","tags":["datetime","time","date","manipulation","deprecated","timezone"],"install":[{"cmd":"pip install moment","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Primary import for the library.","symbol":"moment","correct":"import moment"},{"note":"Often used in conjunction with `moment` objects, which can convert to/from `datetime` instances.","symbol":"datetime","correct":"from datetime import datetime"}],"quickstart":{"code":"import moment\nfrom datetime import datetime\n\n# Get the current moment (UTC)\nnow_utc = moment.utcnow()\nprint(f\"Current UTC Moment: {now_utc.format('YYYY-MM-DD HH:mm:ss')}\")\n\n# Create a moment from a string\ndate_str = \"2023-10-27 10:30:00\"\nmy_moment = moment.date(date_str)\nprint(f\"Parsed Moment: {my_moment.format('YYYY-MM-DD HH:mm:ss')}\")\n\n# Add some time\nfuture_moment = my_moment.add(hours=2, minutes=15)\nprint(f\"Future Moment: {future_moment.format('YYYY-MM-DD HH:mm:ss')}\")\n\n# Convert to a native datetime object\nnative_datetime = future_moment.date\nprint(f\"Native datetime: {native_datetime}\")\n\n# Clone a moment to prevent mutation\noriginal = moment.now()\nmodified = original.clone().add(days=1)\nprint(f\"Original (should be unchanged): {original.format('YYYY-MM-DD')}\")\nprint(f\"Modified (1 day later): {modified.format('YYYY-MM-DD')}\")","lang":"python","description":"This quickstart demonstrates how to create moment objects from current time or strings, perform basic arithmetic operations like adding time, and convert them to standard `datetime` objects. It also highlights the use of `clone()` to handle mutability."},"warnings":[{"fix":"Migrate to `arrow` (e.g., `pip install arrow`) or `pendulum` (e.g., `pip install pendulum`). These libraries offer similar or enhanced functionality with active development and better timezone support.","message":"The 'moment' library is no longer actively maintained (last GitHub activity in 2015) and is considered deprecated. It is recommended to use actively developed alternatives like `arrow` or `pendulum` for robust date/time handling, especially for new projects.","severity":"deprecated","affected_versions":"<=0.12.1"},{"fix":"Always use `.clone()` before performing operations that should not alter the original moment object. Example: `new_moment = original_moment.clone().add(days=1)`.","message":"Moment objects are mutable by default. Operations like `add()` or `subtract()` modify the original moment instance unless `clone()` is explicitly called first. This can lead to unexpected side effects in your code.","severity":"gotcha","affected_versions":"<=0.12.1"},{"fix":"For applications requiring precise and up-to-date timezone awareness, particularly across different regions and DST transitions, consider `pendulum` which is built for strict timezone handling, or `arrow` for a more user-friendly API with timezone awareness. Carefully test all timezone-sensitive operations if you must use `moment`.","message":"The library's timezone handling, while present, may not be as robust or up-to-date with current DST rules and edge cases as more modern alternatives. There are open issues on GitHub related to timezone conflicts.","severity":"gotcha","affected_versions":"<=0.12.1"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install moment` in your terminal to install the package.","cause":"The 'moment' library has not been installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'moment'"},{"fix":"Consult the `zachwill/moment` GitHub README for available methods. If expecting a non-mutated object, ensure you've used `.clone()` before modification. If you are expecting `Moment.js` functionality, be aware that this is a Python port and not all features are identical. Consider `arrow` or `pendulum` if core `moment` functionality is missing or problematic.","cause":"This error often indicates that you are either calling a method that doesn't exist in the 'moment' library, or you are trying to use a method from `Moment.js` (JavaScript library) assuming it exists in the Python `moment` library, or that your 'moment' object has been mutated unexpectedly.","error":"AttributeError: 'Moment' object has no attribute 'some_method_that_should_exist'"},{"fix":"Ensure all `datetime` objects you are comparing are either consistently naive or consistently aware. When converting from `moment` to `datetime`, explicitly handle timezones. For example, `my_moment.date.replace(tzinfo=desired_timezone)` or ensure `moment` objects are consistently aware with `.utcnow()` or `.timezone()` methods, and then use `moment_obj.datetime` to get an aware `datetime`.","cause":"Although `moment` has timezone capabilities, if you convert a `moment` object to a native `datetime` object without explicitly setting or managing its timezone, it might become naive. Comparing a naive `datetime` (no timezone info) with an aware `datetime` (with timezone info) will raise this error.","error":"TypeError: can't compare offset-naive and offset-aware datetimes"}]}