Skip to content

Commit

Permalink
Merge pull request #179 from tonyseek/for-json
Browse files Browse the repository at this point in the history
Add "for_json" method to support simplejson serialization. Thanks @tonyseek
  • Loading branch information
andrewelkins committed Jan 26, 2015
2 parents 4ce24a6 + 912c04a commit f7f9ef3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,9 @@ def strftime(self, format):

return self._datetime.strftime(format)

def for_json(self):
'''Serializes for the ``for_json`` protocol of simplejson.'''
return self.isoformat()

# internal tools.

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ nose==1.3.0
nose-cov==1.6
chai==0.4.0
sphinx==1.2b1
simplejson==3.6.5
7 changes: 7 additions & 0 deletions tests/arrow_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from datetime import date, datetime, timedelta
from dateutil import tz
import simplejson as json
import calendar
import pickle
import time
Expand Down Expand Up @@ -386,6 +387,12 @@ def test_isoformat(self):

assertEqual(result, self.arrow._datetime.isoformat())

def test_simplejson(self):

result = json.dumps({'v': self.arrow.for_json()}, for_json=True)

assertEqual(json.loads(result)['v'], self.arrow._datetime.isoformat())

def test_ctime(self):

result = self.arrow.ctime()
Expand Down

0 comments on commit f7f9ef3

Please sign in to comment.