Maya is a Python library designed to make working with datetimes significantly easier and more intuitive. It wraps Python's built-in `datetime` module, providing a human-friendly API that simplifies common tasks such as parsing diverse date strings, handling timezones, and converting between various time representations. It aims to eliminate common pitfalls like distinguishing between naive and aware datetimes. The current version is 0.6.1, and while releases are infrequent, the project is actively maintained to address user issues.
pip install mayaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to get the current time, parse human-readable date strings, convert datetimes to specific timezones, and generate time intervals using the `maya` library. It showcases the core functionalities of `maya.now()`, `maya.parse()`, `MayaDT.datetime()`, and `maya.intervals()`.
Be explicit with time components if a specific time is desired (e.g., `maya.when('tomorrow 12pm')`), or handle ranges manually if a full-day interval is needed (e.g., `maya.when('2024-01-15').start_of_day()` and `.end_of_day()` if available, or construct `MayaInterval` explicitly).For precise timezone-aware arithmetic, convert to a `datetime` object with the desired timezone using `MayaDT.datetime(to_timezone='...')` and perform arithmetic there, or ensure operations are explicitly done in UTC before converting back to a local timezone.
Check `maya`'s `setup.py` or `pyproject.toml` (if available in a modern release) for current `pendulum` dependency constraints. If encountering issues, try pinning `pendulum` to a known compatible version in your `requirements.txt`.
If parsing fails, try providing date strings in common, unambiguous formats (e.g., 'YYYY-MM-DD HH:MM:SSZ') or fall back to Python's standard `datetime.strptime()` if specific formatting is known.
Ensure `gcc` and `python3-dev` (or equivalent for your OS/Python version) are installed in the Docker image or environment before attempting `pip install maya`.
Ensure the date string provided to `maya.parse()` is in a supported and unambiguous format. Add error handling to check if `maya.parse()` returns `None` before proceeding. For example: `m = maya.parse(date_string); if m is not None: do_something_with(m)`.
Install the library using pip: `pip install maya`
For critical date parsing, provide explicit, standardized date and time strings (e.g., ISO 8601, RFC 2822) rather than relying solely on 'human slang'. If timezones are involved, consider explicitly setting them during parsing using `maya.parse(date_string, timezone='UTC')` or similar methods.