Skip to content

b10011/mongoengine-arrow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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"))

About

Arrow datetime support for MongoEngine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages