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
Built Distribution
Close
Hashes for mongoengine_arrow-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f908b7dc880b3c48ac6d2af18e3d9dff75eb74ffd1db567c0dba1f7f843c2580 |
|
MD5 | ab54f4bff37f4a0372dc7386fefb6e1e |
|
BLAKE2b-256 | 4867fdb3aaa2fe170fc3937c7b6caa8325f74ae8f442b524e5a3c940aebe28ad |