Source

jython-db4o / db4o / util.py

__author__ = 'Sean Summers <SeanSummers@gmail.com>'

import java.util.Date
import java.util.GregorianCalendar
import javax.xml.bind.DatatypeConverter

def encode_jud(o):
    if isinstance(o, java.util.Date):
        return toISO8601(o)
    raise TypeError(repr(o) + ' is not JSON serializable')

def toISO8601(aDate):
    c = java.util.GregorianCalendar.getInstance()
    c.setTime(aDate)
    return javax.xml.bind.DatatypeConverter.printDateTime(c)

def fromISO8601(aDateISO8601String):
    return javax.xml.bind.DatatypeConverter.parseDateTime(aDateISO8601String).getTime()