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.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea65892ba2d8010f56d9c10557a1342b8a0f8028a2c3f7d1e8c10090ea803f8 |
|
MD5 | e1220917c64c363d0bb0dd198a6bf090 |
|
BLAKE2b-256 | c97fab4cb152957a52ce08e1849c5b6efa29cc26cb52e01ad6430ba4ebd5472b |