drf-true-datetime

Custom date time field for DRF to fix bad client time


Keywords
drf, django, datetime
License
MIT
Install
pip install drf-true-datetime==0.1.0

Documentation

drf-true-datetime

Custom date time field for django rest framework that corrects for bad client time PyPI version

What is this sorcery?

If the time on the clients is incorrectly set, and they send bad time data to your APIs, this is for you. (Also, your APIs need to be built on the django-rest-framework).

TrueDateTimeField is a custom date time field that calibrates the value on validation. Whatever is the difference between the correct time (server time) and the client time is added to the date time value.

How to magic?

On the client side, whenever you are making an API request, fetch the current device time. Send this device time as an HTTP header, with key name as Device-Time and value as an ISO date time string. (For example, 2007-04-05T14:30Z or 2007-04-05T12:30-02:00).

On the server side, change the relevant serializer field to be a TrueDateTimeField instead of a mere DateTimeField. That's it! The correction will kick in every time the serializer is validated.

How to update the spell?

We would love to have your contributions! To contribute to the repo, please open an issue or create a pull request.