Skip to main content

Arrow datetime support for MongoEngine

Project description

mongoengine-arrow

Description

Arrow datetime support for MongoEngine

Install

pip3 install --upgrade mongoengine-arrow

How it works

Feed it datetime with or without timezone info in any format Arrow supports. To confirm whether it will work, feed it to arrow.get() function.

Usage example

# Import the field
from mongoengine_arrow import ArrowDateTimeField

...

# Define model
class MyModel(Document):
    timestamp = ArrowDateTimeField(required=True)

...

# Get instance
myinstance = MyModel.objects.first()

# Get timestamp in local time
timestamp = myinstance.timestamp.to("local")

# Set timestamp in any timezone
myinstance.timestamp = arrow.get(2021, 1, 1, tzinfo="UTC")

# Set timestamp from datetime
from datetime import datetime
myinstance.timestamp = datetime(2021, 1, 1)

# Set timestamp from datetime that has tzinfo
from datetime import datetime
from dateutil.tz import gettz
myinstance.timestamp = datetime(2021, 1, 1, tzinfo=gettz("UTC+5"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongoengine-arrow-0.1.3.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

mongoengine_arrow-0.1.3-py3-none-any.whl (3.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page