Skip to content

Commit

Permalink
Fixed timetsamp field receiving ISO instead of timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
OdinsPlasmaRifle committed Aug 6, 2020
1 parent 00b34f6 commit bb800cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions drf_rehive_extras/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from datetime import datetime
from django.utils.timezone import make_aware

from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
Expand Down Expand Up @@ -51,12 +52,11 @@ def to_representation(self, obj):

def to_internal_value(self, obj):
try:
date = datetime.strptime(str(obj), '%Y-%m-%dT%H:%M:%SZ').timestamp()
date = int(obj) / int(self.multiplier)
except ValueError:
raise serializers.ValidationError(
_('Incorrect date format, expected ISO 8601.'))
_('Incorrect date format, must be a valid unix timestamp.')

return datetime.fromtimestamp(int(date))
return make_aware(datetime.fromtimestamp(int(date)))


class EnumField(serializers.ChoiceField):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import find_packages, setup


VERSION = '0.0.8'
VERSION = '0.0.9'

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
README = readme.read()
Expand Down

0 comments on commit bb800cc

Please sign in to comment.