Maya: Datetimes for Humans

0.6.1 · active · verified Mon Apr 13

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.

Warnings

Install

Imports

Quickstart

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

import maya

# Get the current time
now = maya.now()
print(f"Current time: {now}")

# Parse anything
date_obj = maya.parse("tomorrow")
print(f"'Tomorrow' parsed: {date_obj.slang_date()}, {date_obj.slang_time()}")

# Convert to a specific timezone
la_time = now.datetime(to_timezone="America/Los_Angeles")
print(f"Current time in LA: {la_time}")

# Generate time intervals
start = maya.when("2024-01-01")
end = maya.when("2024-01-03")
print("Days in interval:")
for day in maya.intervals(start=start, end=end, interval=60*60*24):
    print(f"- {day.slang_date()}")

view raw JSON →