Advertisement
Guest User

TSergey, 2014-11-19, json timestamp error

a guest
Nov 19th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. # /lib/app/application.py
  2. def to_json(self, v):
  3. """
  4. Convert custom types to json string
  5. :param v:
  6. :return:
  7. """
  8. if v is None:
  9. return None
  10. elif isinstance(v, datetime.datetime):
  11. if hasattr(self.TZ, 'localize'):
  12. return self.TZ.localize(v).isoformat()
  13. else:
  14. return v.replace(tzinfo=self.TZ).isoformat()
  15. else:
  16. raise Exception("Invalid to_json type")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement