Registry / serialization / moment

moment

JSON →
library0.12.1pypypi✓ verified 85d ago

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`.

pip install moment
INSTALL
IMPORT
SIG · MOMENT
M
moment
serializationpythonv0.12.1
Install
3.2s avg
Import
1061ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.12.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.101s · 30.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.2s · import 1.022s · 32MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

moment
import moment
Primary import for the library.
datetime
from datetime import datetime
Often used in conjunction with `moment` objects, which can convert to/from `datetime` instances.

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.

import moment from datetime import datetime # Get the current moment (UTC) now_utc = moment.utcnow() print(f"Current UTC Moment: {now_utc.format('YYYY-MM-DD HH:mm:ss')}") # Create a moment from a string date_str = "2023-10-27 10:30:00" my_moment = moment.date(date_str) print(f"Parsed Moment: {my_moment.format('YYYY-MM-DD HH:mm:ss')}") # Add some time future_moment = my_moment.add(hours=2, minutes=15) print(f"Future Moment: {future_moment.format('YYYY-MM-DD HH:mm:ss')}") # Convert to a native datetime object native_datetime = future_moment.date print(f"Native datetime: {native_datetime}") # Clone a moment to prevent mutation original = moment.now() modified = original.clone().add(days=1) print(f"Original (should be unchanged): {original.format('YYYY-MM-DD')}") print(f"Modified (1 day later): {modified.format('YYYY-MM-DD')}")
Debug
Known issues
deprecatedThe '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.
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.
affects: <=0.12.1
gotchaMoment 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.
fix
Always use `.clone()` before performing operations that should not alter the original moment object. Example: `new_moment = original_moment.clone().add(days=1)`.
affects: <=0.12.1
gotchaThe 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.
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`.
affects: <=0.12.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'moment'
The 'moment' library has not been installed in your current Python environment.
fix
Run `pip install moment` in your terminal to install the package.
AttributeError: 'Moment' object has no attribute 'some_method_that_should_exist'
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.
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.
TypeError: can't compare offset-naive and offset-aware datetimes
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.
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`.
Upgrade
Version history
0.12.1latest on PyPI · released Nov 27, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
4
Resources
moment — pip install moment · libregistry